Announcement

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

  • Merging two datasets

    Hello,

    I need to merge two datasets. I already have one existing dta file, and I converted one csv file to dta,and tried to merge it with the existing dta fie. But whenever I'm trying to do it, it says "merge already defined". Can someone help me out to solve this problem? Thanks.

    Fahmida

  • #2
    Whenever you merge a file, Stata creates a new variable "_merge". Does this variable already exist in your dataset? If so, drop/rename that variable before attempting to merge (or use the gen() option to choose a different name for the variable Stata will create in the merge).
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Thanks. I have got it. However, if I am merging two datasets using a variable, how to make it uniquely identify observations in the existing file? For example, when I merged two datasets by a variable name hsn, it is saying-

      (note: variable hsn was str4, now str25 to accommodate using data's values)
      variable hsn does not uniquely identify observations in the using data

      My question is- how can I make it compatible to identify observations?

      Fahmida

      Comment


      • #4
        the note is not a problem; that hsn is not unique is a problem; you can use the -duplicates- command to find the problems; see
        Code:
        help duplicates
        there are other ways also; e.g.,
        Code:
        sort hsn
        browse hsn if hsn==hsn[_n-1]

        Comment

        Working...
        X