Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Adding normal density to overlayed histograms

From   "Michael N. Mitchell" <[email protected]>
To   [email protected]
Subject   Re: st: Adding normal density to overlayed histograms
Date   Wed, 20 Oct 2010 22:57:28 -0700

Dear Dorothy

The documentation for -help addplot_option- indicates that the -addplot()- option shows that it works like this...

. sts graph, addplot(your_contribution)

the result is that the commands construct

. graph twoway something_complicated || your_contribution

  so your command would translate into

. graph twoway hist x, normal || hist x2, normal

but, unfortunately, -normal- is not a supported option for -graph twoway-, it is only supported for -hist- alone.

Using the -auto- dataset as an example, here is a long way you can create an overlaid histogram of -weight- and -price- with a normal overlay for each...

- snip -
sysuse auto, clear

hist weight, addplot(hist price)

summarize weight
local m1 = r(mean)
local s1 = r(sd)

summarize price
local m2 = r(mean)
local s2 = r(sd)

graph twoway (histogram weight) ///
             (histogram price) ///
             (function normden(x,`m1',`s1'), range(weight)) ///
             (function normden(x,`m2',`s2'), range(price))
- snip -

  I hope that helps,

Best regards,

Michael N. Mitchell
Data Management Using Stata      -
A Visual Guide to Stata Graphics -
Stata tidbit of the week         -

On 2010-10-20 9.39 PM, Dorothy Bridges wrote:
Hi everyone,

I am overlaying two histograms and would like Stata to add a normal
density curve for each.

hist x, normal addplot(hist x2)

works fine, but

hist x, normal addplot(hist x2, normal)

tells me that normal is not an option.  Any ideas as to why this is happening?

*   For searches and help try:
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index