Generating Variable in Stata? -
i have categorical variable , trying calculate new variable multiplies each response frequency. ex:
total | freq. ------------+--------------- 1 | 6 2 | 12 3 | 9 5 | 5 6 | 10
i have variable presents sum n each response (i.e. 1=6, 2=24, 3=27, etc.). tried few calculations using egen, did not seem work. please let me know if has insight.
i think example should show general tactic:
sysuse auto, clear bysort rep78: egen count_rep78 = count(rep78) gen freq_x_val = rep78*count_rep78 browse rep78 count_rep78 freq_x_val
in example rep78 categorical variable.
essentially, create count variable category's frequency in bysort
step. multiply new count variable categorical variable , you're done.
Comments
Post a Comment