I have two loops, with the goal of merging one or two xlsx input files to a central dta. The first foreach loop was composed to save each possible input file to dta, and the second to merge each dta file in the filelist macro to the larger central table. On the merge step, I'm receiving an invalid file specification error, but have not been able to identify any errors in the file path or macros. Any insight, into what may be causing this error is appreciated.
Secondarily, it is possible that the two input files may over-write each other for certain dates. Is it possible to specify that, on conflict, the using file should update and replace the existing data if variable interim=="Non-interim"?
Kind thanks on any insight available.
Code:
dir *.xlsx local filelist: dir "." files "Testing Metrics*.xlsx" di `"`filelist'"' foreach file of local filelist { import excel "`file'", firstrow case(lower) clear local outfile: subinstr local file ".xlsx" "", all sort date save "`outfile'", replace } local filelist_dta: dir "." files "testing metrics*.dta" di `"`filelist_dta'"' *** 2b. Merging monthly dta files using Master Lab Testing Table /// RATIONALE: Using Update replace option for the merge, so that newer using file over-writes /// previous results available in master lab testing file for that same day. foreach file of local filelist_dta { use "`lab_dta'", clear sort date merge 1:1 date using "`filelist_dta'", update replace save "`lab_dta'", replace clear }
Kind thanks on any insight available.
Comment