Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • merge command in a loop

    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

  • #2
    At least for me, your description is a bit confusing. Maybe you could post an example of your dataset and post the code that you have tried so far.
    Your description gives me the impression that you have a dataset in a wide layout. Maybe first converting the dataset from wide to long layout, then appending the datasets and then removing unwanted observations might work.

    Comment

    Working...
    X