Announcement

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

  • How to merge two datasets by one variable?

    Dear all, I want to merge two datasets by age, for every age from 1-120 in my "age" dataset I have for example a different death rate, it looks like this;
    age death rate
    1 ..
    2 ..
    3 ..
    4 ..
    5 ..
    6 ..
    ... ..
    119 ..
    120 ..
    In the other dataset for my population (the using dataset), I have a lot of observations and people who have the same age like this:
    Age Variable 1
    1 ..
    1 ..
    1 ..
    1 ..
    5 ..
    5 ..
    ... ..
    80 ..
    80 ..
    I tried this:
    Code:
    merge m:1 age using "dta-files\populatie_def.dta"
    However, I get the error:
    ''variable age does not uniquely identify observations in the
    using data''

    I understand that this is the case because in the using data there are more persons with the same age. But, how to solve this?

  • #2
    Youre merging the wrong way around.
    Either do:
    Code:
    merge 1:m age using "dta-files\populatie_def.dta"
    But åprobably better is to load the populatie_def.dta into memory, and then do

    Code:
    merge m:1 age using "dta-files\age.dta"
    with the idea being that the master dataset (in memory) has many, and the 'using' dataset in a m:1 has only one observation for each value of age
    Last edited by Jorrit Gosens; 07 Jun 2018, 07:04.

    Comment


    • #3
      Thanks! It works.

      Comment

      Working...
      X