I have a categorical variable and am trying to calculate a new variable that multiplies each response by its frequency. Ex:
total | Freq.
------------+---------------
1 | 6
2 | 12
3 | 9
5 | 5
6 | 10
I would like to have a variable that presents the sum n for each response (i.e. 1=6, 2=24, 3=27, etc.). I tried a few calculations using egen, but they did not seem to work. Please let me know if anyone has any insight.
I think that this example should show you the general tactic:
In this example rep78 is the categorical variable.
Essentially, you create a count variable that is the category's frequency in the
bysort
step. Then you multiply your new count variable by the categorical variable and you're done.