Bookmark and Share

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


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

RE: st: Re overlaying normal curves over multiple histograms


From   "Cohen, Elan" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: Re overlaying normal curves over multiple histograms
Date   Mon, 13 Aug 2012 17:12:38 +0000

Hi Jennifer,

Just to expand a bit on what Nick said, I would try something like this:

sysuse auto
separate mpg, by(foreign)

tw hist mpg0, fc(none) lc(black) || hist mpg1, fc(none) lp(dash) lc(red) || function normalden(x,20,4), ra(10 40) lc(black) || function normalden(x,25,7), ra(10 40) lp(dash) lc(red)

You'll surely want to play around with more of the options, but that should get you started.

HTH,

- Elan


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Monday, August 13, 2012 13:05
To: [email protected]
Subject: Re: st: Re overlaying normal curves over multiple histograms

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 <[email protected]> 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/


*
*   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/


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