Hello,
I have the following loop which reads in multiple files and saves them - I only want to keep certain variables in the files that are read in. All the files will have at least one of the variables listed in the "keep" clause of the code, most will have all three, but some only one, others will have two.
Is there a way to rewrite the code to say, if one or more of the variables listed exist - then keep them? At the moment the code ends in error if one of the variables is not present
foreach x of newlist DEM DEP MH AST COPD CVDPP CAN AF HYP CHD HF STIA RA BP SMOK DPE RTR CHY OSTIA {
use "$path\QOF_`x'.dta", clear
*
keep GPCode Prevalence1920_* PCScore1920_* ExcptRate1920_*
destring _all, ignore(":") replace
save qof_`x'.dta, replace
}
I have the following loop which reads in multiple files and saves them - I only want to keep certain variables in the files that are read in. All the files will have at least one of the variables listed in the "keep" clause of the code, most will have all three, but some only one, others will have two.
Is there a way to rewrite the code to say, if one or more of the variables listed exist - then keep them? At the moment the code ends in error if one of the variables is not present
foreach x of newlist DEM DEP MH AST COPD CVDPP CAN AF HYP CHD HF STIA RA BP SMOK DPE RTR CHY OSTIA {
use "$path\QOF_`x'.dta", clear
*
keep GPCode Prevalence1920_* PCScore1920_* ExcptRate1920_*
destring _all, ignore(":") replace
save qof_`x'.dta, replace
}
Comment