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: calculate maximum density of normal distribuion


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: calculate maximum density of normal distribuion
Date   Tue, 26 Nov 2013 17:50:24 +0000

`=normalden($mean, $mean, $sd)'

where you have

`=normalden(0)'

as the density you need is at the mean and for a normal with specified
mean and SD, not at 0 and for mean 0 and SD 1.

It does not bite you, but -round(anynumber, 0.01)- just produces a
number that is Stata's best approximation to a multiple of 0.01. Stata
can't guarantee to do exact decimal rounding of fractions unless the
decimal fraction concerned is expressible as a binary fraction that
Stata can hold exactly. When people say

local rounded = round(<anynumber>, 0.01)

they would usually be better off with

local rounded : di %3.2f <anynumber>

You could also collapse your -summarize- calls to one and your
-_pctile- calls to 1.


Nick
[email protected]


On 26 November 2013 17:26, Nick Bornschein <[email protected]> wrote:
> Hello Nick,
>
> I finally put all together, but there seems to be one problem I cannot
> solve. I just want to change the mean and sd at the beginning of the syntax
> and automating everything else until the graph. But still with scatteri I
> can not get the xline as I want, please have a look:
>
> clear
>
> set obs 10000
> set seed 2211
> macro drop _all
>
> global mean = 2
> global sd = 2
> gen normal1 = rnormal($mean, $sd)
>
> ***
>
>
> qui: su normal1
> global min = r(min)
> global min = round($min,.01)
> display $min
>
> qui: su normal1
> global max = r(max)
> global max = round($max,.01)
> display $max
>
> _pctile normal1, p(2.5)
> global n1_1 = r(r1)
> global n1_1 = round($n1_1,.01)
> display $n1_1
>
> _pctile normal1, p(97.5)
> global n1_2 = r(r1)
> global n1_2 = round($n1_2,.01)
> display $n1_2
>
> global dens1 = normalden(0,$sd)
> display $dens1
>
> ***
>
> twoway  function normalden(x,$mean,$sd), range($min $max) color(r)  ||
> ///
>         scatteri 0 $mean `=normalden(0)' $mean, recast(line)        ||
> ///
>         function normalden(x,$mean,$sd), range($min $n1_1) recast(area)
> color(dknavy) ||            ///
>         function normalden(x,$mean,$sd), range($n1_2 $max) recast(area)
> color(dknavy)               ///
>         xtitle("{it: {&mu}}")                              ///
> ///
>
>         ytitle("") title("Normalverteilung")
> ///
>         subtitle("{&mu}=$mean {&sigma}=$sd mit {&alpha}=.05, 2-seitig")
> ///
>         legend(off) xlabel($n1_1 $mean $n1_2)
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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