1

我正在尝试动态创建本地变量并通过将值分配给新变量来检查它们

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'
4

1 回答 1

1

明确你local的s必须在同一个名字空间,即交互式会话、do-file、do-file editor、program。要调试,请键入

macro li 

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

于 2013-06-23T23:39:32.157 回答