GroupID | Preferences (1 = movie; 2 = sports) |
1 | 1 |
1 | 2 |
1 | 1 |
2 | 2 |
2 | 2 |
2 | 1 |
2 | 2 |
3 | 1 |
3 | 1 |
For each group, I want to get a data on the number of people that prefer movie.
So my ideal table will something like this:
GroupID | Preferences | No of people preferring movie ( = 1) in the group |
1 | 1 | 2 |
1 | 2 | 2 |
1 | 1 | 2 |
2 | 2 | 1 |
2 | 2 | 1 |
2 | 1 | 1 |
2 | 2 | 1 |
3 | 1 | 2 |
3 | 1 | 2 |
How can I get such a third column in STATA?
I think something along the following lines would work but cannot figure out by myself.
Code:
gen num_movie = . foreach j in var Preferences { replace num_movie = GroupID if `j' == 1 }
0 Response to Finding number of people of a given type for each group
Post a Comment