Announcement

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

  • add one variable from one dataset to another one: error variable V2 does not uniquely identify observations in the master data

    Hell everyone,

    I have a dataset with V2 - country code

    (in the codebook each country has a code so I believe the initial value of the V2 are codes):

    Code:
    tab V2 (master dataset)
    Click image for larger version

Name:	экрана 2019-01-27 в 16.32.33.png
Views:	1
Size:	62.7 KB
ID:	1480735




    I need to add to the dataset the GDP per capita variable. For this I have created the excel file with 2 columns: V2 and GDP per capita and saved this file as .dta.

    As recommended in previous posts I have used
    Code:
    merge 1:1 V2 using "/.../GDP_per_capita.Wave_6.dta"
    Problem: I am receiving the error variable V2 does not uniquely identify observations in the master data no matter if I am having in the GDP dataset country names (to match the V2 from master dataset) or codes correspond to each of the country.

    With names:
    Click image for larger version

Name:	экрана 2019-01-27 в 16.30.35.png
Views:	1
Size:	44.6 KB
ID:	1480733





    With codes for each country:
    Click image for larger version

Name:	экрана 2019-01-27 в 16.31.55.png
Views:	1
Size:	38.9 KB
ID:	1480734





    Could you advise where can be a problem?

    Thanks!

  • #2
    Look at -help merge- and particularly at the difference between 1:1, m:1, and 1:m. I think you will find that you want an m:1 merge.

    Comment


    • #3
      Dear Mike,

      Thank your your answer! It seems that it works now. But I am worried if I created the correct dataset (with GDP) which had to be merged. As now when I am tabulating the average GDP variable in the master dataset (after adding it) i receive the results:

      Click image for larger version

Name:	экрана 2019-01-27 в 17.53.08.png
Views:	1
Size:	67.1 KB
ID:	1480743



      I expected to have in the left part of the column: list with countries and where I have freq. now to have average GDP per capita. Or is it fine?

      Can you confirm if I added it correctly to use for my future model ( GDP per capita as explanatory variable for my logic model:

      Code:
      logit charity_participation sex income_class education happiness averGDPpercapita
      Thanks!

      Comment


      • #4
        I'm sorry, I don't understand what you want. Perhaps someone else will.

        Comment


        • #5
          Perhaps the following will allow you to confirm that the merge worked as you expected it.
          Code:
          tabstat AverageGDPpercapita, by(country) statistics(n min mean max)

          Comment


          • #6
            Thanks!

            Comment

            Working...
            X