Announcement

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

  • Merging based on older values of a variable

    Hi All,

    I have data that resembles the following (it is at the individual level):

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(year GDPrate age22 individual)
    1990 3 1982  1
    1991 4 1983  2
    1992 5 1990  3
    1993 1 1992  4
    1994 2 1993  5
    1995 3 1994  6
    1996 3 1995  7
    1997 1 1996  8
    1998 2 1997  9
    1999 1 1998 10
    2000 2 1999 11
    end
    In the above, I have current year, GDP growth rate in the current year, the year an individual turns 22 as well as an individual indentifier. I wish to create another variable, GDPrate22 , which is basically the GDP rate in the year when the individual turned 22. Currently, I have done the following:


    Code:
    set more off
    tempfile master
    save `master'
    keep year GDPrate
    duplicates drop
    rename (year GDPrate) (age22 GDPrate22)
    merge 1:m age22 using `master'
    drop _merge
    Simply, I keep only the year and GDPrate variables, and then rename year to age22. This then allows me to merge back GDPgrowth rate for when individuals are 22, as this does not vary at the individual level.
    Is there a cleaner way of doing this? I feel that I am missing something doing this in this manner- in particular, when I do this for the state level (GDP growth at the state level), I get a lot of missing values in the merge.

    Kind Regards,
    CS

  • #2
    How big is your dataset and what's the timeframe? It's possible that the values truly are missing.

    If it is only 1990-2000 then you won't have a GDPrate22 for anyone who turned 22 previous to 1989 nor anyone who turned 22 post 2000. This would be identified by _merge==2 and is what happens with individuals 1 and 2.

    The other possibility is that while you might have GDPrate22 for the year, there's no one who turned 22 that year. This would be identified with _merge==1

    Comment

    Working...
    X