Combined Graphs

By Jacob White · Published 4 December 2026
graphicsstata

The combined graph takes separate graphs which are created with separate data sets and merges them.

The combined graph can be created using this code:

sysuse auto, clear
twoway__histogram_gen mpg , gen(h y, replace) freq bin(10) // a special command for creating data used in histograms
twoway (histogram y [fw=h] if inrange(y,19,35), discrete lcolor(stc2) freq) ///
       (histogram y [fw=h], color(none) lcolor(stc2) discrete freq name(a1, replace))
twoway (histogram y [fw=h] if inrange(y,19,35), discrete lcolor(stc2) freq name(a2, replace))
graph combine a1 a2 ,xcommon cols(1)
15 views 0 found this useful