Announcement

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

  • How do I impute a missing value with a value I have for a given year (1999) within a panel dataset?

    Dear Stata Forum,

    I have an unbalanced panel dataset for which I have a variable x whose value I only observe in the year 1999.
    Within a given individual, I would like to replace the missings for this value before 1999 and after 1999 with the value I observe in 1999 for this individual.
    I would highly appreciate your assistance with this matter.
    Have a great day,
    Best,
    Nico


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(id year x)
      687 1991  .
     1367 1991  .
     1367 1992  .
     2051 1991  .
     2051 1992  .
     2051 1993  .
     2727 1991  .
     2727 1992  .
     2727 1993  .
     2727 1998  .
     2727 1999 -8
     2727 2000  .
     2727 2001  .
     3407 1991  .
     3407 1992  .
     3407 1993  .
     3407 1994  .
     3407 1998  .
     3407 1999  .
     3407 2001  .
     3407 2002  .
     3407 2005  .
     4091 1991  .
     4091 1992  .
     4091 1993  .
     4091 1994  .
     4091 1995  .
     4767 1991  .
     4767 1992  .
     4767 1993  .
     5451 1991  .
     5451 1992  .
     5451 1993  .
     5451 1995  .
     6135 1991  .
     6135 1992  .
     6135 1993  .
     6807 1991  .
     6807 1992  .
     6807 1993  .
     6882 1997  .
     6882 1998  .
     7487 1991  .
     7487 1992  .
     7487 1993  .
     7487 1994  .
     7487 1996  .
     8167 1991  .
     8167 1992  .
     8167 1993  .
     8167 1995  .
     8167 1996  .
     8847 1991  .
     9527 1991  .
     9527 1992  .
     9527 1993  .
     9527 1994  .
     9527 1995  .
     9527 1996  .
     9527 1997  .
     9527 1998  .
     9527 1999 20
     9527 2000  .
     9527 2002  .
     9527 2003  .
    10211 1991  .
    12251 1991  .
    12251 1992  .
    12251 1993  .
    12251 1994  .
    12251 1995  .
    12251 1997  .
    12251 1998  .
    12251 2000  .
    12251 2001  .
    12251 2002  .
    12251 2003  .
    12251 2004  .
    12935 1991  .
    12935 1992  .
    12935 1993  .
    12935 1995  .
    12935 1997  .
    12935 1998  .
    12935 2000  .
    13607 1991  .
    14287 1991  .
    14287 1992  .
    14287 1993  .
    14287 1994  .
    14287 1995  .
    14287 1996  .
    14287 1997  .
    14287 1998  .
    14287 1999 16
    14287 2000  .
    14971 1991  .
    14971 1992  .
    14971 1993  .
    14971 1994  .
    end

  • #2
    for which I have a variable x whose value I only observe in the year 1999
    The year is irrelevant here then. Just sort and replace. Nonmissing numerical values are sorted before missing.

    Code:
    bys id (x): replace x= x[1]

    Comment


    • #3
      Dear Andrew,
      This is exactly what I needed.
      Thanks so much for your help.
      Have a great day!
      Best,
      Nico

      Comment

      Working...
      X