Hi,
I am using a panel data set with separate waves sorted into separate files each with the same ending "_indresp.dta". The file structure within the directory "~/datafiles" looks something like "ba_indresp.dta", "bb_indresp.dta", "bc_indresp.dta" etc until "br_indresp.dta" so 18 files to loop over. I am using a foreach loop to aggregate each file into a single one, "clean.dta", as shown:
However, the issue is that it only reaches the "bj_indresp.dta" file before ending the loop meaning the remainder of the files are not appended to the aggregate "clean.dta" file.
Any help would be appreciated, thanks.
I am using a panel data set with separate waves sorted into separate files each with the same ending "_indresp.dta". The file structure within the directory "~/datafiles" looks something like "ba_indresp.dta", "bb_indresp.dta", "bc_indresp.dta" etc until "br_indresp.dta" so 18 files to loop over. I am using a foreach loop to aggregate each file into a single one, "clean.dta", as shown:
Code:
local files: dir "~/datafiles" files "*_indresp.dta" local dir1 "~/datafiles" foreach f of local files { local w = substr(`"b`f'_"', 1, 3) use `"b`f'"', clear keep `w'a `w'b `w'c rename `w'* * append using `"`dir1'/clean.dta"' save `"`dir1'/clean.dta"', replace }
Any help would be appreciated, thanks.
Comment