Overlaying histograms in Stata

For analysing data and comparing distributions, I often want to overlay two histograms. Without further options, however, one distribution usually overlays the other and makes comparisons cumbersome. It is possible to set a few options to make the figure look nice.

twoway (hist VAR1, frac lcolor(gs12) fcolor(gs12)) (hist VAR2, frac fcolor(none) lcolor(red)), legend(off) xtitle("VAR1 (red: VAR2)")

In this example, the bars of variable VAR2 have a red border and transparent body, whereas VAR1 is shown as in its default colors (both border and body is set to gs12).

Graph

 

 

3 thoughts on “Overlaying histograms in Stata

  1. Thanks. This is very helpful. Is there a way to overlay a normal curve on top of each histogram. STATA does not seem to like the “normal” option when using twoway

Leave a Reply