If you want to superimpose normal curves on the two histograms, it becomes a little more complicated. Althought Stata can easily overlay a normal distribution over a free-standing histogram with the norm option, that option is not supported for overlayed histograms. Instead, we have to use function plots with normal density arguments.

Here's an example of some further modified code to do that.

*** BEGIN STATA CODE ***

sysuse auto

quietly summarize mpg if foreign

local var1mean: display %6.2f r(mean)

local var1sd: display %6.2f r(sd)

local var1min: display %6.2f r(min)

local var1max: display %6.2f r(max)

quietly summarize mpg if !foreign

local var2mean : display %6.2f r(mean)

local var2sd: display %6.2f r(sd)

local var2min: display %6.2f r(min)

local var2max: display %6.2f r(max)

twoway (histogram mpg if !foreign, start(10) width(2) fraction bfcolor(none) blcolor(brown)) (histogram mpg if foreign, fraction start(10) width(2) barw(1.8) bfcolor(none) blcolor(navy)) (function y=normalden(x, `var1mean', `var1sd') , range(`var1min' `var1max') lcolor(navy)) (function y=normalden(x, `var2mean', `var2sd') , range(`var2min' `var2max') lcolor(brown)) , xlabel(10(5)45, labsize(small)) ylabel(, angle(horizontal) labsize(vsmall) format(%3.2f)) legend(order(1 "Domestic" 2 "Foreign") pos(2) ring(0) col(1)) note(" " "MPG Domestic: {it:M} = `var2mean' {it:SD} = `var2sd'" "MPG Foreign: {it:M} = `var1mean' {it:SD} = `var1sd'", size(vsmall)) scheme(s1color)

*** END STATA CODE ***

If you just want the normal density lines overlayed without the histograms, you can use the following (after loading the data and creating the locals as above).

*** BEGIN STATA CODE ***

twoway (function y=normalden(x, `var2mean', `var2sd') , range(`var2min' `var2max') lcolor(navy)) (function y=normalden(x, `var1mean', `var1sd') , range(`var1min' `var1max') lcolor(brown)) , xlabel(10(5)45, labsize(small)) ylabel(, angle(horizontal) labsize(vsmall) format(%3.2f)) legend(order(1 "Domestic" 2 "Foreign") pos(2) ring(0) col(1)) note(" " "MPG Domestic: {it:M} = `var2mean' {it:SD} = `var2sd'" "MPG Foreign: {it:M} = `var1mean' {it:SD} = `var1sd'", size(vsmall)) ytitle("") xtitle("MPG") scheme(s1color)

*** END STATA CODE ***