Recently I am attempting to deal with some .dta files in a local directory on the desktop. I need to amend each file with the same process and append them into a single file. I was trying to use the local and foreach command to loop over the files. However, the code always returns an error of cannot find the file.dta. My code is as the following:
Code:
cd "C:\Users\Administrator\Desktop\ICE Monthly data\Datasets" local filelist : dir "C:\Users\Administrator\Desktop\ICE Monthly data\Datasets" file "*.dta" foreach file of local filelist{ use file, clear decode _filename, generate(filename) }
file file.dta not found
I attempted to quote the file in line 3 with single and double quotes but the result remains the same.
Cai Hanyi
0 Response to Question on looping over files in a directory using local and foreach
Post a Comment