Dear Statalisters,
I'm new to loops in Stata. I have ~50 files with exactly the same variables in them and wanting to generate same new variables for each file. I tried this:
clear
cd "E:\test"
local list : dir . files "*.dta"
foreach f of local list {
gen person_id=patid
drop patid
save "`f'.dta", replace
clear
}
But then got this error message:
patid not found
r(111);
Could you please advise how to fix this problem?
Many thanks
I'm new to loops in Stata. I have ~50 files with exactly the same variables in them and wanting to generate same new variables for each file. I tried this:
clear
cd "E:\test"
local list : dir . files "*.dta"
foreach f of local list {
gen person_id=patid
drop patid
save "`f'.dta", replace
clear
}
But then got this error message:
patid not found
r(111);
Could you please advise how to fix this problem?
Many thanks
Comment