Hello,

I am trying to get rid of observations from gvkey where fyear does not include either 2014 or 2015. This happens at gvkey: "016289" and "016331" for example. I have tried the following code:
Code:
bysort gvkey (fyear): drop if (missing (fyear[2014]) & missing(fyear[2015]))
. When I use this code, it deletes all observations.
I have tried looking for answers, but I cannot seem to find out how to drop groups of observations conditioned on an if statement.
Could you please help me fix this problem?

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str6 gvkey double fyear
"008546" 2014
"008546" 2015
"008546" 2016
"013145" 2014
"013145" 2016
"013145" 2017
"013556" 2014
"013556" 2017
"013683" 2014
"013683" 2015
"013683" 2017
"014447" 2015
"014447" 2016
"014447" 2018
"015319" 2014
"015319" 2015
"015319" 2016
"015319" 2017
"015321" 2014
"015321" 2016
"015334" 2014
"015334" 2015
"015334" 2017
"016267" 2015
"016267" 2017
"016289" 2016
"016331" 2016
"016331" 2017
"016332" 2015
"016332" 2017
end