求助各位大神两个关于循环语句的问题:
(1)像下面这样的依次递增变量个数的累加,能否用循环语句实现呢?
egen f_2000 = rowtotal(rela_2000)
egen f_2001 = rowtotal(rela_2000 rela_2001)
egen f_2002 = rowtotal(rela_2000 rela_2001 rela_2002)
egen f_2003 = rowtotal(rela_2000 rela_2001 rela_2002 rela_2003)
egen f_2004 = rowtotal(rela_2000 rela_2001 rela_2002 rela_2003 rela_2004)
...
(2)像下面这个例子:每个allrela_20xx.dta里面有关于其前一年变量,需要统一改名称:
use allrela_2001.dta
rename rela_2000 rela_qian
save allrela_2001,replace
use allrela_2002.dta
rename rela_2001 rela_qian
save allrela_2002,replace
use allrela_2003.dta
rename rela_2002 rela_qian
save allrela_2003,replace
...
我的代码是:
forvalues i=2001/2013{
use allrela_`i'.dta
rename rela_`i-1' rela_qian
save allrela_`i',replace
}
但是结果出不来,想问问`i-1'这个用法是不是错的?加入j=i-1似乎也不可行