id | groups | variable% |
1 | 1 | 50 |
1 | 1 | 50 |
1 | 2 | 25 |
1 | 3 | 23 |
2 | 2 | 100 |
2 | 2 | 100 |
2 | 2 | 100 |
3 | 1 | 100 |
Hi,
I have dataset having more than 100k observations. I would like to generate a variable that would allow me calculate the percentages of the number of each "groups" within "id".
For example, I would like to generate "variable%" as a percentage of group values within groups i.e. 50% values in id=1 are spanned over group 1, 25% for group 2 and 3 (and so on for every id)
I have tried egen command as: bysort id : egen total_id = count(id) - which allows me to calculate the totals of each id. But I am not able to figure out how to calculate percentages within groups. Any help in this regard would help a lot.
Comment