You are not logged in. You can browse but not post. Login or Register by clicking 'Login or Register' at the top-right of this page. For more information on Statalist, see the FAQ.
Thanks Robert. I guess I lucked out not having the kids of variations you put forward. I will change the code to conform to your suggestion just in case.
Because I landed on this post when i was looking for a solution i thought it best to post my version, as inspired by Robert Picard's post:
capture use ALL_append // to start with an empty variable list to append data to
drop _all
gen empty= ""
save All_append, replace
drop _all
// search for files with element hr + ending fl.dta
filelist, pat(*HR*FL.DTA) save (filedir) replace
use filedir
gen file = dirname + "/" + filename // create variable with full file path
save filedir, replace
levelsof file, clean local(filelist)
foreach f in `filelist'{
use `f', clear //load each dataset ** keep chosen variables as listed in Vorgehen.docx
local masterlist "hhid hv000 hv001 hv002 hv006 hv007 hv024 hv025 hv201 hv204 hv206 hv271 sh110m shres"
local keeplist = ""
*** following checks if variables i would like to keep (masterlist) do exist adds existing to keeplist
foreach i of local masterlist {
capture confirm variable `i'
if !_rc {
local keeplist "`keeplist' `i'"
}
}
keep `keeplist'
append using All_append
save All_append, replace
use filedir // to be able to repeat the cycle
}
Please Excuse i don't yet know how to post code in a forum. The red part is not needed just a few additional data cleaning commands
Comment