如何在Python中创建一个Stata本地宏? [英] How do I create a stata local macro in python?

查看:28
本文介绍了如何在Python中创建一个Stata本地宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我编辑我的问题以澄清。以下是PYTHON代码:

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中实现的想法?

推荐答案

类似的内容大致相当:

for x in ["apple", "banana", "orange"]:
    with open(x + ".data", "w") as outfile:
        outfile.write("whatever")

这篇关于如何在Python中创建一个Stata本地宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆