I have multiple .dta files from one dataset located in a folder. I would like to create a loop that creates a unique "id" variable within each .dta and then merges all .dta files on that variable.
Presently, I am coding:
use "H16A_R.dta"
rename *, lower
egen id=concat(hhid pn)
save a_r, replace
use "H16B_R"
rename *, lower
egen id=concat(hhid pn)
merge 1:1 id using a_r
drop _merge
save 2016_v2, replace
.....
And so on...
I would like to do something like this:
foreach x.dta in "E:\filename\subfilename\foldername\subfoldern ame" {
rename *, lower
egen id=concat(hhid pn)
merge 1:1 id
drop _merge
save 2016_v2, replace
}
However, when I execute the immediately above, I receive a r:198 "Invalid Name."
Is there any way to do what I'm trying or must it be done the old fashioned way?
Thank you all,
Trent
Presently, I am coding:
use "H16A_R.dta"
rename *, lower
egen id=concat(hhid pn)
save a_r, replace
use "H16B_R"
rename *, lower
egen id=concat(hhid pn)
merge 1:1 id using a_r
drop _merge
save 2016_v2, replace
.....
And so on...
I would like to do something like this:
foreach x.dta in "E:\filename\subfilename\foldername\subfoldern ame" {
rename *, lower
egen id=concat(hhid pn)
merge 1:1 id
drop _merge
save 2016_v2, replace
}
However, when I execute the immediately above, I receive a r:198 "Invalid Name."
Is there any way to do what I'm trying or must it be done the old fashioned way?
Thank you all,
Trent