Announcement

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

  • Generate an initial variable for a specific year

    Hello everyone,

    I have panel data with several countries countries over a specific time period. Now I want to generate a new variable which takes the value from a specific year for all years. For example: I have GDP data from 1970 to 2010, and I want to generate a variable that takes the GDP value from 1980 for all years (by country).

    I already know the command
    bys id: gen gdp_ini = gdp[11]
    ,

    but since not all countries start in the same year I want to tell Stata to use the GDP value from year=1980. Any suggestions? Help would be highly appreciated!

  • #2
    Assuming that each country has only one observation with year == 1980:

    Code:
    by id, sort: egen gdp_ini = max(cond(year == 1980, gdp, .))

    Comment


    • #3
      See https://www.stata-journal.com/articl...article=dm0055 for more general discussion.

      Comment

      Working...
      X