identify groups with few observations in paneldata models (stata)

Viewed 60

How can I identify groups with few observations in panel-data models?

I estimated using xtlogit several random effects models. On average I have 26 obs per group but some groups only record 1 observation. I want to identify them and exclude them from the models... any suggestion how? My panel data is set using: xtset countrycode year

1 Answers

Let's suppose your magic number for a big enough panel is 7 and that you fit a first model.

   bysort countrycode : egen n_used = total(e(sample)) 

then gives you a count of how many observations were available and can be used, after which your criterion for a later model is if n_used >= 7

You could just go

bysort countrycode : gen n_available = _N 

regardless of a model fit.

The differences are two-fold:

  1. That last statement would disregard any missing values in the variables used in a model fit.

  2. If you also used if and/or in to restrict model fit to particular subsets of observations, then e(sample) knows about that, but the last statement does not.

Related