Search code examples
stata

Drop a block of observations if any value is missing within that block


I have 10 years of data for all firms from Compustat from 2010 to 2020. I want to drop any firm which does not have an entry for any of these 10 years. In short I want only those firms that have the entire 10 years of data. How can I do this?


Solution

  • bysort firmid (whatever) : drop if missing(whatever[_N]) 
    

    Missings sort to the end of a block of values, so if any value of whatever is missing in a block it will show up at the end.