Hello!
I have a dataset that I want to merge with a sequence of files that correspond to individual years. I want to merge only those cases with the second file that have not been merged with the first file, and so on. It is possible that a case appears in every of the files, thus I need an identifier for which merger file is used too.
I tried a "foreach + numlist" loop but I don't know how to (or if even possible to) implement the "merge" command in this.
Alternatively, I tried to start the loop with those cases that have not been merged with a previous file. But I would need to rename "_merge" first to allow a following merge and the merger would only affect cases under the condition that they have not been merged already.
Applied to the case, I have a list of firms with an ID. The ID is used to merge them with a sequence of files that contain their location L. A firm can appear in more than only one file, that's why the ID itself is insufficient. I could generate a variable "year" first to identify the file and use only the latest year a firm is listed.
Hope someone can help.
Andreas Knabe
Related Posts with merge command in a loop
Moderated Mediation in Panel Data analysisHi everyone, Please, can anyone guide me on conducting a moderated mediation model using panel data?…
ppml_panel_sg: "r(2000) no observations" error after 10 iterationsHello everyone, I'm currently working with a balanced panel dataset on bilateral exports at the sec…
Plot graph of multiple categorical variables (with sub-categories) across outcome variableDear all, I more than two categorical variables with two sub groups in each. I want to graph them o…
Variable transformations and the meaning of . in chi2(2) columnHow I read these . signs in col chi2(2) in this picture? Array From stata instructions I have unde…
Fixed-effects in svy strata?Hi all, My query is regarding fixed-effects in stratified survey data. I am working with cross-sec…
Subscribe to:
Post Comments (Atom)
0 Response to merge command in a loop
Post a Comment