Announcement

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

  • work with two datasets

    hello everyone,

    i have two datasets. lets call them A and B

    The first one (A) includes many variables, the one of interest here is the birth year.
    individual ... birth year
    1 ... 1960
    2 ... 1996
    3 ... 1982
    ... ... ...
    1000 .. 1968

    the second dataset (B) is just a list of years with coresponding values.
    year value
    1950 12
    1951 11
    ... ...
    1999 14

    Is there any way to create a new variable in dataset A, which takes the value from B, if the variable birthyear from A matches the variable year from B ?

    I could not find any topic with a similar problem, and already looked into the help section for merge and egen. Also tried to work with different frames. nothing worked.


    Thanks.

  • #2
    Yes, -merge- and -frlink- both apply here. Since you mention you can use frames, I would recommend -frlnk-.

    Something like this (pseudocode based on your example, typos are my own). Spend some time reading the -frames- manual if -frlink- seems foreign to you.

    Code:
    frame change A
    frlink m:1 birth_year , frame(B year) gen(lyear)
    frget value, from(lyear)

    Comment


    • #3
      Thank you very much! thats what i tried to do for two days

      Comment

      Working...
      X