I'd like to recode (reverse) a list of 24 dichotomous variables (0/1).
The following should illustrate the problem:
Code:
webuse auto, clear
gen foreign_copy1 = foreign
gen foreign_copy2 = foreign
gen foreign_copy3 = foreign
gen foreign_copy4 = foreign
gen foreign_copy5 = foreign
foreach v of var(foreign ///
foreign_copy1 ///
foreign_copy2 ///
foreign_copy3 ///
foreign_copy4 ///
foreign_copy5) {
recode `var' (0 = 1 "named") (1 = 0 "not named"), gen(`var'_e)
}
"too few variables specified", same using wildcards:
Code:
foreach v of var(foreign foreign_copy*) {
recode `var' (0 = 1 "named") (1 = 0 "not named"), gen(`var'_e)
}
(The real - confidential - data of course have different distributions in each of the 24 variables, but the code stays the same,)
Bye
0 Response to "too few variables" foreach
Post a Comment