Gregor wrote
I have an unbalanced panel and would like to delete all the observations
for which I don't have the whole date range.
year panelid x
1 1 5
2 1 3
3 1 4
1 2 7
3 2 4
In this example I would like to delete panelid 2. So that in the end I
have data for every possible year for every panelid. I tried to drop if
the sum of the years is not equal to the sum of all the 6 years I have
data for (1998 to 2003), but that just left me with the last year of my
data.
I used bysort panelid: drop if sum(year) ~= 12003
bysort panelid: drop if _N < 6
Remember that under a by-list _n means the current obs. and _N means
the last obs. So for an unbalanced panel, _N will be 6 for every
complete unit, and less than that for the ones you want to zap.