Announcement

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

  • data merge: r(459);

    Hi,
    I have two panel data-set and what to merge the two data set. I use the following code but I receive the error "r(459); variable firmid does not uniquely identify observations in the master data". I double-checked for duplicate observation and no duplicate observation reported. I would be grateful if you help regarding the error.

    Code: megre dataset1 with dataset2
    merge 1:1 firmid using dataset2
    or
    merge m:1 firmid using dataset2

    Kindly,
    Mahmoud



  • #2
    how did you check this? try:
    Code:
    sort firmid
    count if firmid==firmid[_n-1]
    do this in each data set

    you could also use the -duplicates command-; see
    Code:
    help duplicates
    or try
    Code:
    duplicates report firmid
    again, do this in each file

    Comment


    • #3
      Rich:
      Both data set are in panel data. I thought is I should use the following code for checking the duplicate. As you see in follow, when I run the code1 the result shows no duplicate. While, when I run code 2 (your suggested code) which do not contain -year- it shows different results. I am not sure how to fix this.


      Code 1:

      . duplicates report firmid year

      Duplicates in terms of firmid year

      --------------------------------------
      copies | observations surplus
      ----------+---------------------------
      1 | 2208 0
      --------------------------------------

      .

      Code 2:

      . sort firmid

      . count if firmid==firmid[_n-1]
      1,840

      .
      . duplicates report firmid

      Duplicates in terms of firmid

      --------------------------------------
      copies | observations surplus
      ----------+---------------------------
      6 | 2208 1840
      --------------------------------------

      Comment


      • #4
        there are two obvious possibilities but there may be others if you supply more info about what is going on: (1) merge on both firmid and year; (2) use either -joinby- or -cross-

        Comment


        • #5
          I am not following you perhaps. I tried cross and joinby but it didn't work well. I have been using -merge- much time. This is the first time I am facing this problem. Could you please let me know how to apply -joinby- and -Cross- in my case. I could not well understand the example from Stata help.

          Thanks in advance!

          Comment


          • #6
            I think you should try the first suggestion that Rich Goldstein made in #4:

            Code:
            merge 1:1 firmid year using dataset2
            When you want to merge panel data, you usually need to specify both the panel variable and the time variable.

            Comment


            • #7
              Thank you Rich and Clyde. As you suggested, I tried to merge with both firmid and year thus it works well.

              Kindly,
              Mahmoud

              Comment

              Working...
              X