Dear All, I found this question here (http://bbs.pinggu.org/forum.php?mod=...=1#pid55292851). The data (I have modified) is here
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte(id x)
1 2
1 2
1 2
1 2
2 4
2 4
2 4
2 4
2 4
2 4
3 1
3 1
3 1
end
Note that for each `id', the values of `x' are the same.

The purpose is, for each `id', to keep the number of `x' with the value of `x'. For example, when id=1, the value of `x' is 2. So, I'd like to keep 2 observations for this id. Similarly, for id=2, the value of `x' is 4. As such, I want to keep four observations for this id=2. Any suggestions?