Code:
* I first import the Excel file (demo.xlsx) to get all the sheet names (the sheet names are A, B, C, etc.):
import excel using "demo.xlsx", describe
* I import the first .dta file as the master file (A.dta)
use "~/Desktop/A.dta", clear
* I then loop through the rest of the sheets to merge
forvalues sheet=1/(`=r(N_worksheet)'-1) {
local sheetname=r(worksheet_`sheet')
merge 1:1 earliest using "`sheetname'.dta"
drop _merge
}
0 Response to Merge multiple .dta files in a folder
Post a Comment