我試圖動態創建的當地人,並通過一個新的變量如何在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'
令人驚訝的是,'recode'容忍「」。我不知道第二個陳述中的錯誤是什麼。 –