Hi ,
I am wondering How to loop on all CSV files in several folders and create a separate dta files .
for example :
Sample for input files :
C:\folder\country1\year1\filename1.csv
C:\folder\country1\year1\filename2.csv
C:\folder\country1\year1\filename3.csv
C:\folder\country2\year2\filename1.csv
C:\folder\country2\year2\filename2.csv
C:\folder\country2\year2\filename3.csv
Sample for output files :
C:\folder\country1\year1\filename1.dta
C:\folder\country1\year1\filename2.dta
C:\folder\country1\year1\filename3.dta
C:\folder\country2\year2\filename1.dta
C:\folder\country2\year2\filename2.dta
C:\folder\country2\year2\filename3.dta
foreach country in country1 country2 country3 { ;
foreach year in year1 year2 year3 { ;
foreach file in "filename*.csv" { ;
cd "C:\folder\`country'\`year'" ;
import delimited using "filename*.csv", case(preserve) clear ;
gen file ;
};
};
} ;
Related Posts with How to loop on all CSV files in several folders and create a separate dta files
Dropping observations is missing valuesHello community, I've downloaded a big dataset with data missing across multiple variables in no re…
Exporting the table results of qrprocess to excel or wordHi STATALIST, I need advice on how I can export the table results of qrprocess to excel or word. R…
nicelabels downloadable from SSCThanks as ever to Kit Baum, a new package nicelabels is now downloadable from SSC. It may be thought…
Control variables for difference-in-differenceHi all, I have been struggling to get help on this I have sales data during an intervention (the i…
Different results for weighted median using same Stata Manual Methodology [Stata/SE 15.0]Hello everyone, I found something about weighted medians in Stata/SE. To my knowledge and what I ha…
Subscribe to:
Post Comments (Atom)
0 Response to How to loop on all CSV files in several folders and create a separate dta files
Post a Comment