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
9 Month back for date of birthHi, I have data on b1 (month of birth) and b2 (year of birth). I want to go back 9 (nine) months fro…
Reshape multiple years observations from wide to longDear all, my current data structure is as follows: DATA CompanyID 2011 2012 2013 … 2019 VarOfIn…
Store and export p values from pwcorr in a loopI am running correlations for ~3,000 variables. The nuance of the usefulness of p values versus conf…
How do I estimate a first order autoregressive equation with firm and year fixed effects ???I am really new to Stata and I need to estimate the following empirical specification on Stata for m…
lclogit inquiryHi everyone, I'm new to Stata. I'm trying to classify individuals from which I have data in a series…
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