Announcement

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

  • Drop observation with complicated criterion (panel)

    Hi,

    I'm dealing with a panel dataset of firms interviewed once a year for the period between 2010 and 2020.
    I'd want to investigate the impact of a policy introduced in 2015, so I'd need to eliminate from my dataset all those observations about firms interviewed, let's say, just in 2012, or just in 2018, or in 2013 and 2014, or in 2017 and 2018.
    In other words, I want to keep only those firms that have been interviewed at least once before 2015 AND at least once after 2015.
    Every observation in my dataset have a variable gpkey (i.e. the firm identification code) and a variable year (i.e. the reference year), together obviously with other variables of interest.

    I can't find a way to keep only the observations relative to the firms that satisfy the criterion explained above.

    Very grateful to whomever may help me out, I wish you all Merry Christmas

    Best,

    Mike

  • #2
    Code:
    bysort gpkey (year): generate tokeep = year[1]<2015 & year[_N]>2015
    keep if tokeep

    Comment


    • #3
      thanks!

      Comment

      Working...
      X