Hello,
I have different files (.dta) in folder "C:\Users\Desktop\Stata\Data". I would like to loop over all the files in that folder, keep some variables, and append the resulting files.
I do the following loop, in which I try to pick every file in the folder, select variables "var1", "var2", and "var3", save the new file with the selected variables with a new name (the original name of the file plus an a), and append the resulting files in a new dataset call List1. It does not give any error, but it's not working, it's not producing anything. Any idea?
I have different files (.dta) in folder "C:\Users\Desktop\Stata\Data". I would like to loop over all the files in that folder, keep some variables, and append the resulting files.
I do the following loop, in which I try to pick every file in the folder, select variables "var1", "var2", and "var3", save the new file with the selected variables with a new name (the original name of the file plus an a), and append the resulting files in a new dataset call List1. It does not give any error, but it's not working, it's not producing anything. Any idea?
Code:
clear all cd "C:\Users\Desktop\Stata\Datos" local files: dir "C:\Users\Desktop\Stata\Datos" files "*" foreach file in `files' { use `file'.dta, clear keep var1 var2 var3 save `file'a.dta append using `file'a save List1.dta, replace erase `file'a.dta }
Comment