I have a situation where I need to import all the files in a directory and append them. My code is this
local files : dir "C:Usersxx" files "*.xls"
local n: word count `files'
tokenize ``files''
cd "C:Usersxx"
forval k =1/`n'{
foreach file in `files' {
import excel "`file'", sheet("Time Sheet") clear
drop in 3
if `k' == 1 {
di in red `k'
save "C:Usersxxmaster.dta", replace
}
else {
append using "C:Usersxxmaster.dta"
}
save "C:Usersxxmaster.dta", replace
}
}
However when I use this code it seems to run an extra loop (* forval k =1/`n'*) that create duplicate entries. I cannot get rid of that code since I need it for the append command. I was wondering whether there is a way to mitigate this problem.
See Question&Answers more detail:os