Hi all, I am a Stata 16 user. I work in this project where we have to download data in .xlsx forms. The forms do not retain the same name with every download as the date of import is appended on the end of the file name. This generally makes it harder to download and run a cleaning and merging do file. To make the process a little bit automatic, in have used
to help me turn the respective files to .dta files. Now I believe if I could shell rename the files (there are 31 of them) into numbers from 1-31 then this would allow me to easily merge them without necessarily handling the string names. I wrote a loop to do this but from my end it do produces no error or no output. The file names do not change. my code is
Any help to debug this will be highly appreciated.
Regards
xls2dta : import excel . , firstrow allstring
**** list of all files in the folder
local fils : dir . files "*.dta"
di `fils'
**** sort the file list
local fils: sort `fils'
**** renaming files sequentially. no 1-31
local i = 1
foreach file of local fils {
local newname "`i'.dta"
shell rename "`file'" "`newname'"
di "rename `file' to `newname'"
local i = `i' + 1
}
local fils : dir . files "*.dta"
di `fils'
**** sort the file list
local fils: sort `fils'
**** renaming files sequentially. no 1-31
local i = 1
foreach file of local fils {
local newname "`i'.dta"
shell rename "`file'" "`newname'"
di "rename `file' to `newname'"
local i = `i' + 1
}
Regards
Comment