Hi Statalist,
I want to draw a graph similar to the following plot. I would appreciate any insights.
Thanks,
I want to draw a graph similar to the following plot. I would appreciate any insights.
Thanks,
ssc install floatplot , replace h floatplot
b | a | x | y | z |
0 | 0 | 8 | 6.1 | 110 |
0 | 0 | 6 | 5.7 | 98 |
0 | 1 | 11 | 5.7 | 81 |
0 | 0 | 7 | 6.1 | 102 |
0 | 1 | 9 | 5.3 | 84 |
0 | 1 | 8 | 7.7 | 184 |
0 | 0 | 6 | 8.1 | 177 |
0 | 0 | 9 | 7 | 130 |
1 | 0 | 6 | 6.5 | 113 |
1 | 1 | 8 | 6.6 | 122 |
1 | 1 | 6 | 7.3 | 170 |
1 | 0 | 3 | 6.6 | 125 |
1 | 1 | 7 | 6.8 | 120 |
1 | 0 | 5 | 7.4 | 140 |
1 | 1 | 7 | 6.7 | 160 |
* Example generated by -dataex-. For more info, type help dataex clear input byte(b a x) float y int z 0 0 8 6.1 110 0 0 6 5.7 98 0 1 11 5.7 81 0 0 7 6.1 102 0 1 9 5.3 84 0 1 8 7.7 184 0 0 6 8.1 177 0 0 9 7 130 1 0 6 6.5 113 1 1 8 6.6 122 1 1 6 7.3 170 1 0 3 6.6 125 1 1 7 6.8 120 1 0 5 7.4 140 1 1 7 6.7 160 end foreach v in x y z { egen mean_`v' = mean(`v'), by(a b) egen mean_0 = mean(cond(a == 0, `v', .)), by(b) egen mean_1 = mean(cond(a == 1, `v', .)), by(b) gen wanted_`v' = mean_0 - mean_1 drop mean_0 mean_1 } sort b a list b a *x *y *z , sepby(b a) +--------------------------------------------------------------------------------------------+ | b a x mean_x wanted_x y mean_y wanted_y z mean_z wanted_z | |--------------------------------------------------------------------------------------------| 1. | 0 0 9 7.2 -2.133333 7 6.6 .3666668 130 123.4 7.066666 | 2. | 0 0 8 7.2 -2.133333 6.1 6.6 .3666668 110 123.4 7.066666 | 3. | 0 0 6 7.2 -2.133333 5.7 6.6 .3666668 98 123.4 7.066666 | 4. | 0 0 7 7.2 -2.133333 6.1 6.6 .3666668 102 123.4 7.066666 | 5. | 0 0 6 7.2 -2.133333 8.1 6.6 .3666668 177 123.4 7.066666 | |--------------------------------------------------------------------------------------------| 6. | 0 1 8 9.333333 -2.133333 7.7 6.233333 .3666668 184 116.3333 7.066666 | 7. | 0 1 11 9.333333 -2.133333 5.7 6.233333 .3666668 81 116.3333 7.066666 | 8. | 0 1 9 9.333333 -2.133333 5.3 6.233333 .3666668 84 116.3333 7.066666 | |--------------------------------------------------------------------------------------------| 9. | 1 0 3 4.666667 -2.333333 6.6 6.833333 -.0166664 125 126 -17 | 10. | 1 0 6 4.666667 -2.333333 6.5 6.833333 -.0166664 113 126 -17 | 11. | 1 0 5 4.666667 -2.333333 7.4 6.833333 -.0166664 140 126 -17 | |--------------------------------------------------------------------------------------------| 12. | 1 1 7 7 -2.333333 6.7 6.85 -.0166664 160 143 -17 | 13. | 1 1 6 7 -2.333333 7.3 6.85 -.0166664 170 143 -17 | 14. | 1 1 7 7 -2.333333 6.8 6.85 -.0166664 120 143 -17 | 15. | 1 1 8 7 -2.333333 6.6 6.85 -.0166664 122 143 -17 | +--------------------------------------------------------------------------------------------+
bysort b : keep if _n == 1 keep b wanted* reshape long wanted_, i(b) j(which) string separate wanted_, by(which) veryshortlabel twoway bar wanted_? b, by(which, note("") yrescale row(1) legend(off)) yla(#4) base(0) barw(0.5 .. ) xla(0 1) ytitle(informative text here)
Comment