Announcement

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

  • Numeric merge codes hard to remember -- alternatives?

    After a merge statement, I often inspect the merged data and decide whether I want to keep rows with _merge==1 (master), _merge==2 (using), _merge==3 (matched). I have trouble remembering what 1,2,3 mean and would much rather use words than numbers.

    I'm aware of the keep option to the merge command --e.g.,
    Code:
    merge 1:1 using otherdata, keep(match master)
    But I'm often unsure which results I want to keep until I've inspected the data. So what I'm talking about is more like this.
    Code:
    merge 1:1 using otherdata
    list if _merge==1
    drop if _merge==1
    Is there a more transparent alternative to saying _merge==1 here?

    Thanks!
    Paul



  • #2
    not sure what you are looking for, but Stata offers the alternative of including the label in the command instead of just the number; the values labels for merge are saved under the name "_merge" and could be used as follows:
    Code:
    list if _merge=="Master only (1)":_merge
    added - of course you don't have to remember all this; just -tab _merge- and then copy-and-paste from the output (or use label list and then copy)

    Comment


    • #3
      Thanks, Rich! At the end of your command, what does :_merge represent?
      Unfortunately, this doesn't get me out of memorizing the numeric codes, because they're part of the value label -- e.g., "Master only (1)".

      Comment


      • #4
        first the _merge represents the name of the value label - the describe command will always give you that

        second, no, you don't have to remember anything; just use either "label list _merge" and copy-and-paste what you want or "tab _merge" and, again, copy-and-paste

        Comment


        • #5
          You could also
          Code:
          local master    1
          local using     2
          local matched   3
          then
          Code:
          ...
          list if _merge == `master'
          If you do that often, store the local macro definitions (adding codes 4 and 5 if needed) in a do-file, then
          Code:
          ...
          include do-file
          list if _merge == `master'
          Last edited by daniel klein; 14 Aug 2025, 13:18.

          Comment

          Working...
          X