Hey folks,
im pretty new to stata and trying to merge different variables into 1 variable for ~20 datafiles with a loop.
I have different Housholds in the datasets which are identified with the variable names q1a, q1b, q1c, paid and hhid. This variables shall be merged into the single variable HH_ID across the 20datasets in my file. In order to do so I tried different commands:
Try1:
local files : dir"C:\Users\User\Desktop\Master\Thesis\Data\Data Cleaning\Required Data Files" files "*.dta*"
foreach file in `files' {
generate HHID = string(q1a) + string(q1b) + string(q1c) + string(paid) + string(hhid)
save `files', replace
}
Stata: unexpected end of file
Try2:
local myfilelist : dir"C:\Users\User\Desktop\Master\Thesis\Data\Data Cleaning\Required Data Files" files "*.dta*"
dir `myfilelist'
foreach datafile of local myfilelist {
generate HH_ID = string(q1a) + string(q1b) + string(q1c) + string(paid) + string(hhid)
save "*.dta*", replace
}
Stata: unexpected end of file
Using only the command " generate HH_ID = string(q1a) + string(q1b) + string(q1c) + string(paid) + string(hhid)" it is possible to merge and create the new variable, so this one works, however the loop does not.
Can someone give me advice how to alter this command to run that loop?
Thank you in advance!
Related Posts with foreach loop variables
Collapsing two variables that occur multiple timesHi StataList, I'm attempting to collapse two variables, "from_gstin" and "to_gstin", into a form wh…
Storing and graphing the lincom estimates (inside the loop)After running the regression, I did the lincom, and then stored the estimates (with local as well as…
Any suggestions on addressing endogeneity while estimating Veblen Effect.How do I make sure that price coefficient is positive because the good is veblen or there is unadres…
An event study plot in STATA - multiple, staggered & temporary treatment with spillover effectsHello! Disclaimer - Apologies for any inconsistency in the posting format, I have read instructions…
Creating biological and step families with the new ADD Health Parent DataHello Statalist! I am fairly new at analyzing data and I am hoping someone will be able to help me …
Subscribe to:
Post Comments (Atom)
0 Response to foreach loop variables
Post a Comment