Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Re overlaying normal curves over multiple histograms |
Date | Mon, 13 Aug 2012 18:04:58 +0100 |
There's a subtlety here. The first mention of -histogram- is running the stand-alone -histogram- command, which permits the -normal- option, but the second mention of -histogram- within -addplot()- is a call to -twoway histogram-, which doesn't. If I take your code literally, you just know, or find it convenient to suppose, that you have two normal distributions. In this case, the heart of the problem is to superimpose the density functions, and for that purpose one line suffices twoway function normalden(x, 123.5, 17) , ra(50 200) || /// function normalden(x, 127.9, 17), ra(50 200) Simulating large samples to get approximations to each normal is then unnecessary. If your real problem involves real data, however, and is not as stated here, then you will need to extend your -addplot()- call to add a call to -function- as above. Nick . On Mon, Aug 13, 2012 at 5:37 PM, Jennifer Dent <JDent@sgul.ac.uk> wrote: > Hello, > > I am trying to overlay two histograms, both with normal distributions added. > I am able to add a normal line to the first histogram, and to add a second > histogram using addplot, but I am not able to add a second normal line. Is > there a way to do this? I want the y-axis presented as percentage (or > frequency) and not density and wonder if this is where my problem might be? > > My code, along with the error, is given below: > > clear > set obs 10000 > gen WE = rnormal(123.5, 17) > sort WE > gen SA = rnormal(127.9, 17) > sort SA > > histogram WE, percent normal addplot(histogram SA, percent normal) > > error: option normal not allowed r(198) * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/