Hi, I would need some help with the following problem please, I'm a new STATA user:

I have a list of firms from COMPUSTAT from 1950 to 1998. I need to hold the number of firms constant between 1968 and 1998 (meaning that I need to keep the firms that existed for all those 31 years). Also, I have to keep those firms between 1950 and 1967, that still existed in 1998. I'm posting a photo of the sample I need to create- firms from 1668 and 1998 are steady 896, but firms before that period are those that existed both in that year and in 1998.
I know how to create a constant sample between 1968 and 1998- that is I need to use:
keep if fyear>=1968
keep if fyear<=1998
bys conm: gen nyear=[_N]
keep if nyear==31
But I don't know how to create the additional period of 1950- 1967 in the same file.