gpt4 book ai didi

python - 如何在 python 中创建 stata 本地宏?

转载 作者:太空宇宙 更新时间:2023-11-03 15:56:27 24 4
gpt4 key购买 nike

让我编辑我的问题来澄清。这是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 中,我认为不允许在变量名中混合 string 和 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 - 如何在 python 中创建 stata 本地宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40729173/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com