我正在尝试动态创建本地变量并通过将值分配给新变量来检查它们
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'