Announcement

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

  • Using frlink/frget in place of merge

    I am trying to work with the frlink and frget commands instead of merge, and I am running into problems. I typically use a loop to merge multiple files together. I first import them from CSV, clean them, then save as stata files. Finally, I merge them. I was hoping with frlink and frget that I could skip the step of saving as stata files, but frlink doesn't seem to work the same way as merge. It only takes data from other frames with keys that exist in the "working" frame, which doesn't work for my purposes. I want all observations to be copied into the working frame, whether they are matched or not. Is there something I am missing here?

  • #2
    frlink followed by frget are equivalent to merge, keep(master match). If you are interested in merging, then use merge. My approach is to use a temporary file which I recycle whenever I need to merge or append a frame. It only costs me one line of code. Over time, these features may be introduced to frames.

    Code:
    *ASSIGN A NAME TO A RECYCLABLE TEMPORARY FILE
    tempfile holding
    
    input float id value
    1 7
    2 9
    3 11
    4 13
    end
    
    frame create new
    frame change new
    input float id value2
    1 7
    2 9
    3 11
    4 13
    5 15
    6 17
    7 19
    end
    
    frame change default
    *SAVE FRAME TO RECYCLABLE TEMPORARY FILE (ALWAYS -REPLACE-)
    frame new: save `holding', replace
    merge 1:1 id using `holding'
    Res.:

    Code:
    . l, sep(7)
    
         +--------------------------------------+
         | id   value   value2           _merge |
         |--------------------------------------|
      1. |  1       7        7      matched (3) |
      2. |  2       9        9      matched (3) |
      3. |  3      11       11      matched (3) |
      4. |  4      13       13      matched (3) |
      5. |  5       .       15   using only (2) |
      6. |  6       .       17   using only (2) |
      7. |  7       .       19   using only (2) |
         +--------------------------------------+
    Last edited by Andrew Musau; 13 Jul 2020, 13:39.

    Comment


    • #3
      Oh, nice! Thank you very much

      Comment


      • #4
        What about a case where we have 5 datasets?

        Comment

        Working...
        X