Hello all,
I am working on recoding the variables of various datasets based on their own properties. The basic rule is that if there is more than 5% missing information, then that missing information should be coded to missing (=.) instead of being allowed to remain in its original form (-99 -97).
I've built the following program which works well until the last macro. It appears that Stata is recalling the first variable as * instead of each individual variable like it did in the first macro.
local all_vars * (Trying to indicate all of the original variables in the dataset)
foreach var of local all_vars {
cap noi recode `var' (-99=1) (-97=1) (else=0), pre(missing_)
}
*
foreach var of varlist missing_* {
egen frac_`var'= mean(`var')
}
*
foreach var of local all_vars { *This is where the code fails because it reads the first variable as “*” instead of the lsit of variables used earlier
recode `var' (-99 -97=.) if frac_missing_`var'>.05 }
}
Any thoughts on how to avoid this error?
I am working on recoding the variables of various datasets based on their own properties. The basic rule is that if there is more than 5% missing information, then that missing information should be coded to missing (=.) instead of being allowed to remain in its original form (-99 -97).
I've built the following program which works well until the last macro. It appears that Stata is recalling the first variable as * instead of each individual variable like it did in the first macro.
local all_vars * (Trying to indicate all of the original variables in the dataset)
foreach var of local all_vars {
cap noi recode `var' (-99=1) (-97=1) (else=0), pre(missing_)
}
*
foreach var of varlist missing_* {
egen frac_`var'= mean(`var')
}
*
foreach var of local all_vars { *This is where the code fails because it reads the first variable as “*” instead of the lsit of variables used earlier
recode `var' (-99 -97=.) if frac_missing_`var'>.05 }
}
Any thoughts on how to avoid this error?
Comment