The double loop is causing the problem:
local files : dir "D:/Datos/rferrer/Desktop/statatemps" files "test*.xls"
cd "D:/Datos/rferrer/Desktop/statatemps"
local counter = 1
foreach file in `files' {
import excel "`file'", sheet("Hoja1") firstrow clear
if `counter' == 1 {
di in red `counter'
save "D:/Datos/rferrer/Desktop/statatemps/master.dta", replace
}
else {
append using "D:/Datos/rferrer/Desktop/statatemps/master.dta"
save "D:/Datos/rferrer/Desktop/statatemps/master.dta", replace
}
local counter = 0
}
list
You don't use the tokens created by tokenize
, so you can drop it.
Shorter would be:
clear
set more off
local pathdir "D:/Datos/rferrer/Desktop/statatemps"
local files : dir "`pathdir'" files "test*.xls"
save "`pathdir'/master.dta", emptyok replace
foreach file in `files' {
import excel "`file'", sheet("Hoja1") firstrow clear
append using "`pathdir'/master.dta"
save "`pathdir'/master.dta", replace
}
list
You might want to read help quotes
if for some reason you have "weird" file names (and because it's a good read anyway).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…