import - Importing .csv files and saving as .dta -


i have folder containing number of csv files, e.g. "leeds dz.csv", "leeds gh.csv", "leeds fr.csv". first part of file names constant (i.e. "leeds").

i want import each stata individually, convert .dta file , save it. have code:

cd "etcetc" clear local myfilelist : dir . files"*.csv" foreach file of local myfilelist { drop _all insheet using `file', comma local outfile = subinstr("`file'",".csv","",.) save "`outfile'", replace } 

the code works fine if rename .csv files manually delete "leeds" part, ie if each .csv named "dz.csv" instead of "leeds dz.csv" etc.

however, if not deletion receive error "invalid 'dz.csv' "

i'm guessing has 3rd line of code, in particular "*.csv". i'm unsure how adapt code/ why won't allow me import files space in name?

the line

insheet using `file', comma 

will problematic filename containing spaces.

try

insheet using "`file'", comma 

the insheet quite explicit on this:

if filename specified without extension, .raw assumed. if filename contains embedded spaces, remember enclose in double quotes.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -