I have a large data with around 20,000 observations where V1 is the household ID that gives out one IDs per household. Another variable that I want to use is V2 which is labelled either 1,2,or 3. I want to figure out how many V2=3 there are for each household ID and make that as a new variable.
For example, if this is what the data looks like:
V1 | V2 | NEW VAR |
10 | 1 | 1 |
10 | 2 | 1 |
10 | 3 | 1 |
11 | 2 | 0 |
11 | 2 | 0 |
I have read some threads on this matter and tried egen, count method that was recommended but did not succeed.
I feel like this is a simple problem and I am sorry for the repetition in question.
Thank you in advance!
P.S. I use STATA 14.0 for Mac
0 Response to How to count number of observations per id
Post a Comment