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 Bornschein <[email protected]>
To   [email protected]
Subject   Re: st: calculate maximum density of normal distribuion
Date   Tue, 26 Nov 2013 18:26:00 +0100

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/


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