Hi, I have many excel files in the directories 1998 to 2016 (so, there are 19 directories). In each directory, there are different numbers of excel files, namely, from 4 (in directory 1998, the file names are TRD_Dalyr1998-1.xls to TRD_Dalyr1998-4.xls) to 11 (in directory 2016, the file names are TRD_Dalyr2016-1.xls to TRD_Dalyr2016-11.xls). I'd like to import those files, save them in Stata format, and then append/merge them into a file for further analysis. How can I do this? Thanks. I tries the following (but it is likely to be wrong!):
Code:
forvalues t=1998(1)2016 { forvalues i=1(1)11 { cap import excel "`t'\TRD_Dalyr`t'-`i'.xls", firstrow clear drop in 1/2 save "TRD_Dalyr`t'-`i'.dta", replace } }
Comment