如何在Stata中即时创建本地人? [英] How to create locals on the fly in Stata?
本文介绍了如何在Stata中即时创建本地人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试动态创建本地人,并通过将值分配给新变量来检查它们
I am trying to create locals on the fly and check them by assigning values to a new variable
gen sampleVar =.
foreach i in AK AL AR AZ {
su income if (year==2012 & state_nsw == "`i'"), meanonly
local val_`i' = r(mean)
display "`val_`i''"
}
// check the local
recode sampleVar .= "`val_AL'"
// this is what I get:
5242.57421875
.....
5352.66796875
. invalid name
r(198);
// check 2 the local
recode sampleVar .= `val_AL' // error
答案:我的问题是我尝试过
ANSWER: My problem was that I tried
recode sampleVar .= `val_AL' + `val_AZ'
// this is inappropriate.
//the correct way is:
local try = `val_AL' + `val_AZ'
recode sampleVar .= `try'
推荐答案
请注意,您的local
必须位于相同的名称空间中,即交互式会话,执行文件,执行文件编辑器,程序.要调试,请输入
Be clear that your local
s must be in the same name space, i.e. interactive session, do-file, do-file editor, program. To debug, type
macro li
在recode
语句之前,以查看哪些宏是可见的.
before the recode
statement to see what macros are visible.
这篇关于如何在Stata中即时创建本地人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文