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?
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.
by id
id
_N
1.4m articles
1.4m replys
5 comments
57.0k users