dropping firms in paneldataset

#1
Hi all,
I have the following panel of firms:
A balanced panel of firms:

FirmID Year Respondvariable
1 0 30
1 1 40
1 2 30
1 3 30
1 4 30
2 0 40
2 1 263
2 2 .
2 3 .
2 4 .
In year 0 all firms either have 40 or 30 on the respond variable. Now I want to delete all firm ID’s ( I,e all firms for all 5 years) that do NOT have at least one time 30 or 40 in the subsequent years, 1,2,3,4.
Does anybody have any suggestions on how to do this in stata?

Thanks in advance,

Carmen
 

bukharin

RoboStataRaptor
#2
One simple way is to create an indicator variable to indicate whether the firm satisfies your condition (1=the year isn't zero and the respond variable is 30 or 40, 0=anything else), then drop any firms where the maximum value of the indicator isn't 1:
Code:
gen byte has30or40=Year!=0 & (Respondvariable==30 | Respondvariable==40)
by FirmID (has30or40), sort: drop if !has30or40[_N]