Announcement

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

  • Four years consecutive data

    Hi, i have a panel data with id and year between 1997-2003. I want to delete observations without four years consecutive data, the minimum number necessary to estimate the regression models. So that means that I want to keep for example this observation: 1997 1998 2000 2001 2002 2003 or 1998 1999 2000 2001 2003. But I want to delete the observation for example: 1997 2001 2002 2003 or 1997 1998 1999 2001 2002 2003. I hope someone can help me, it would be really important! Thank you!

  • #2
    xtpatternvar (SSC) -- although a little out of date in a way that will not bite you -- can help here.

    Here is a demonstration.

    Code:
    ssc install xtpatternvar 
    webuse abdata, clear
    xtpatternvar, gen(history)
    tab history
    
        history |      Freq.     Percent        Cum.
    ------------+-----------------------------------
      ..1111111 |         14        1.36        1.36
      .1111111. |        273       26.48       27.84
      .11111111 |        152       14.74       42.58
      1111111.. |        434       42.10       84.68
      11111111. |         32        3.10       87.78
      111111111 |        126       12.22      100.00
    ------------+-----------------------------------
          Total |      1,031      100.00
    In your case you are wanting to


    Code:
    keep if strpos(history, "1111")
    as any four 1s in succession will suffice.

    Comment

    Working...
    X