Announcement

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

  • Dropping values within range, while preserving others.

    I am quite new to Stata and did some thorough research on how to do the following, but didn't seem to get it done properly.

    Currently I am trying to clean my dataset which looks something like this:
    ID Year Cash
    1 2008 20
    1 2009 23
    1 2010 21
    1 2011 18
    2 2009 52
    2 2010 51
    2 2011 50
    3 2009 12
    3 2010 14
    I want to keep only the ID's that include all of the years 2008-2011 and drop all observations that only have a subset of those. (my dataset is far bigger than this, hence dropping manually doesn't work)

    However, everything I tried has not worked out so far so I was hoping one of you could help me out a bit here.


    Cheers,

    Moos
    Last edited by Moos Janssen; 26 Apr 2022, 04:12.

  • #2
    Assuming that there is no year that precedes 2008:

    Code:
    isid ID Year
    bys ID (Year): gen tag= Year[4]==2011
    keep if tag
    If there are years preceding 2008 in the sample, you need to create an indicator for the 4 year period and then proceed as above.

    Comment

    Working...
    X