让我编辑我的问题来澄清。下面是Python代码:如何在python中创建一个stata本地宏?
decade_begin = 1970
while decade_begin <= 1994:
for x in range(0, 10):
a= decade_begin + x
decade_begin = a+1
decade_end=a
print "year_",decade_begin,"s" #start year
最后一行的输出是:
year_1980s
year_1990s
我希望能够创建一个变量,使得:
year_1990s = [a]
在Stata这很容易,使用本地宏'x'。但在Python中,我认为混合字符串和int在变量名是不允许的。
forval i = 1979/1994 {
whatever if year == `i'
save year_`i'.dta, replace
}
有关如何在python中实现的任何想法?
对于那些熟悉Python但不熟悉STATA的人,你能解释一下'x'是什么吗?你的意思是像[格式文字](http://stackoverflow.com/documentation/python/1019/string-formatting/4021/format-literals#t=201611212058243848285)? –
我认为它在STATA被称为本地宏。我找到的最简单的解释是:https://www.ssc.wisc.edu/sscc/pubs/stata_prog1.htm – Carla
它**被称为本地宏。这在源码http://www.stata.com/help.cgi?foreach上是非常明确的但我怀疑Stata [NB]术语是否有助于回答python问题,这是一个如何遍历列表的问题。 –