Hi,
I have around 2000 files and I want to loop over them. The problem is that some of those file names do not exist. For the ones that do exist, I want to save them as a Stata dataset. Regarding the ones that do not exist, I do not want anything to happen.
c is a global for all the names.
If I run the mentioned code, it does not jump over the files that do not exist an it creates new Stata files with those names.
How should I fix this?
Best
I have around 2000 files and I want to loop over them. The problem is that some of those file names do not exist. For the ones that do exist, I want to save them as a Stata dataset. Regarding the ones that do not exist, I do not want anything to happen.
Code:
foreach x in $c { di "`x'" cap: import delimited using "C:/Users/39349/Documents/Courses/`x'", clear if _rc!=0 { display "file exists" save "C:/Users/39349/Documents/Courses- Stata/`x'", replace } else if _rc==0 { display "file does not exist" exit } }
If I run the mentioned code, it does not jump over the files that do not exist an it creates new Stata files with those names.
How should I fix this?
Best
Comment