问题
I have longitudinal data on individuals (id) surveyed in two years. Some individuals were not surveyed the second time. I would like to drop all outcomes on individuals surveyed only once so that I am left with a balanced data set.
How do I do this in Stata?
回答1:
This might do it for you:
by id, sort: drop if _N!=2
The by id
will execute the command following the colon separately for each value of id
, and _N
will be the number of observations with that id
.
来源:https://stackoverflow.com/questions/36926272/drop-observations-in-panel-data-using-stata