Suppose i have the following variables:
I would like to create a composite variable var5 that takes the following values:
1 4,457
2 3,392
3 1,428
4 700
How can i do that? The combination of egen with group() as suggested in other posts creates all combinations.
Code:
. set obs 10000 obs was 0, now 10000 . gen var1 = rbinomial(1,0.446) . gen var2 = rbinomial(1,0.339) . gen var3 = rbinomial(1,0.142) . gen var4 = rbinomial(1,0.073) . tab var1 var1 | Freq. Percent Cum. ------------+----------------------------------- 0 | 5,543 55.43 55.43 1 | 4,457 44.57 100.00 ------------+----------------------------------- Total | 10,000 100.00 . tab var2 var2 | Freq. Percent Cum. ------------+----------------------------------- 0 | 6,608 66.08 66.08 1 | 3,392 33.92 100.00 ------------+----------------------------------- Total | 10,000 100.00 . tab var3 var3 | Freq. Percent Cum. ------------+----------------------------------- 0 | 8,572 85.72 85.72 1 | 1,428 14.28 100.00 ------------+----------------------------------- Total | 10,000 100.00 . tab var4 var4 | Freq. Percent Cum. ------------+----------------------------------- 0 | 9,300 93.00 93.00 1 | 700 7.00 100.00 ------------+----------------------------------- Total | 10,000 100.00
1 4,457
2 3,392
3 1,428
4 700
How can i do that? The combination of egen with group() as suggested in other posts creates all combinations.
Comment