Stata/Probability Function

From Wikibooks, open books for an open world
Jump to navigation Jump to search

The list of probability functions is available by typing in the command editor :

h density functions

Useful quantiles[edit | edit source]


. di invnorm(.975)
1.959964

. di invchi2(1,.95)
3.8414588

Standard distributions[edit | edit source]

Gaussian Distribution[edit | edit source]

local q975 = invnormal(.975)
#delimit ; 
tw function  y = normalden(x) , range(-4 4) ||
	, xlabel( , grid)
	xline( -`q975' `q975')
	title(PDF Gaussian with 95 % CI)
	; 
#delimit cr
gr export W:/normal.png, replace

The Gaussian distribution with 90,95 and 99 % confidence intervals.

set scheme s2color
global ub10 = invnorm(.95)
global lb10 = invnorm(.05)
global ub5 = invnorm(.975)
global lb5 = invnorm(.025)
global ub1 = invnorm(.995)
global lb1 = invnorm(.005)
#delimit ;
tw  function y=normden(x), range(-4 $lb5) color(red) recast(area)
      ||  function y=normden(x), range($ub5 4)   color(red) recast(area)
      ||  function y=normden(x), range(-4 4) lstyle(foreground)
      ||,
       ysca(off) xsca(noline)
       legend(off)
        xlabel(-4 "-4 sd" -3 "-3 sd" -2 "-2 sd" -1 "-1 sd" 0 "mean"
                      1  "1 sd"  2  "2 sd"  3  "3 sd"  4  "4 sd"
                      , grid gmin gmax)
              xtitle("")
          ;
#delimit cr  

Student Distribution[edit | edit source]

#delimit ; 
tw function  y = tden(1,x) , range(-4 4) ||
	function y = tden(2,x) , range(-4 4) ||
	function y = tden(5,x) , range(-4 4) ||
	function y = tden(10,x) , range(-4 4) ||
	function y = tden(30,x) , range(-4 4) ||
	function y = normalden(x) , range(-4 4) lw(thick) ||
	, xlabel( , grid)
	legend(cols(5) label(1 "k=1") label(2 "k=2") label(3 "k=5") 
 label(4 "k=10") label(5 "k=30") label(6 "Gaussienne"))
	title(PDF Student Distribution)
	; 
#delimit cr
Previous: Documentation Index Next: Random Number Generation