Dear statalisters!
I want to ask if I can use foreach loop to keep variables of interst from each year and create one big file that contains income and expenses variables only.
1. File names include year , eg. data1990svy.dta; data1991svy.dta ; data1992svy.dta etc
2. in each file, income and expenses variables have also year suffix (e.g totinc1990 netinc1990 medexp1990 pocexp1990
I tried to use foreach loop. but I am lost.
I appreciate any help, thanks in advance
Rob
foreach file in C:\project\data1990svy.dta `
do I have to list all the data file names after foreach
foreach file in `C:\project\data*svy.dta' {
keep totinc* netinc* med* exp*
sort id
merge 1:1 using `C:\project\data*svy.dta'
save "`C:\project\ALL_SVY.dta'
}
I beleive this loop will save me time, instead of creating a file for each year, then merge them. Thanks
Comment