如何在Stata中动态创建当地人?

时间:2013-06-23 23:36:07

标签: local stata

我正在尝试动态创建本地化并通过为新变量赋值来检查它们

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
答案:我的问题是我试过

 recode sampleVar .= `val_AL' + `val_AZ'
// this is inappropriate.
//the correct way is:
local try = `val_AL' + `val_AZ'
recode sampleVar .= `try'

1 个答案:

答案 0 :(得分:1)

请注意,您的local必须位于相同的名称空间中,即交互式会话,do-file,do-file编辑器,程序。要进行调试,请键入

macro li 

recode语句之前查看哪些宏可见。