Announcement

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

  • Merge various .dta with one command

    Hi,
    I'm working with various .dta files that have one common variable.
    Do you know how can I merge all them with 1 command without doing it 1 by 1?
    Many thanks.
    Best Regards,
    Yevhen

  • #2
    Unlike -append-, which can combine a whole bunch of files in a single command, -merge- can only do them one at a time. Now, you don't have to write out a large number of -merge- commands. You can create a list of the files you want to merge in a local macro and the write a -foreach- loop over that list with a single -merge- command inside it. If you want help with coding that, you'll need to provide more information.

    Added: By the way, just because I've seen so many people fall into this trap, remember that just because files have a variable in common is no guarantee that they can be merged together. Also, even if they can, sometimes that's not the best approach to combining them. For example, if the common variable is a list of entities, and each file consists of certain properties of those entities in a different year, then -append-ing those files would produce a more usable result than -merge-ing them. Anyway, before you set out on this, you should first assure yourself that these files can and should be -merge-d. Otherwise you'll waste a lot of time and get really frustrated.
    Last edited by Clyde Schechter; 08 May 2018, 17:08.

    Comment


    • #3
      Dear Yevhen, Please (ssc) install mergemany, and read the help file.
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment

      Working...
      X