Hi,
consider the following data structure:
For every firm-executive combination I only want to keep those observations referring to the first two years which are different from each other.
That is, the Firm-Executive combination 4295899290-18101 should only have one entry for the year 2010, as all of its observations are linked to 2010.
4295899290-35166 should have two entries, one for 2011 and another for 2012.
My approach does work (I guess) but seems a bit complex so I was wondering whether there is a more elegant approach to obtain the same result.
Thank you!
consider the following data structure:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input double FirmID long ExecutiveID int Year 4295899290 18101 2010 4295899290 18101 2010 4295899290 18101 2010 4295899290 35166 2011 4295899290 35166 2012 4295899290 35166 2012 4295899290 35166 2012 4295899290 35166 2012 4295899290 35166 2013 4295899290 35166 2013 4295899290 35166 2013 4295899290 35166 2013 4295899290 35166 2014 4295899290 35166 2014 4295899290 35166 2014 4295899290 35166 2014 4295899290 35166 2015 4295899290 35166 2015 4295899290 35166 2015 4295899290 35166 2015 end
For every firm-executive combination I only want to keep those observations referring to the first two years which are different from each other.
That is, the Firm-Executive combination 4295899290-18101 should only have one entry for the year 2010, as all of its observations are linked to 2010.
4295899290-35166 should have two entries, one for 2011 and another for 2012.
My approach does work (I guess) but seems a bit complex so I was wondering whether there is a more elegant approach to obtain the same result.
Code:
sort FirmID Year ExecutiveID egen tag = tag(FirmID ExecutiveID Year) gen fyind = Year if tag != 0 drop if missing(fyind) bysort FirmID ExecutiveID: gen abs= _n keep if abs<=2
Comment