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
Match each treated country to a non-treat country that is adjacent and has the closest crime rate in year t-1Dear StataList-ers! Help! I need somebody! My question is very basic but I’m absolutely lost. I am …
zero inflated Panel data (Interrupted Time series)Hello Experts, I have panel data set which is zero inflated (99%). I am planning to do an Interrupt…
Rolling Regression for cross sectionBelow is the code that i used to calculate monthly residuals following Fama and French three Factor …
Football and Covid, problem in including some teamsGood Evening. I am dealing with a project in Econometrics, in which I have to see what is the effec…
FRM estimation in panel dataDear researchers, I estimate balanced panel data N = 77, T = 6, in which the dependent variable is …
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