/************************************************************************** Understaning the Poisson Probability Distribution Author: Hun Myoung Park First created: 03/06/2013 Last modified: 03/06/2013 ****************************************************************************/ global mu=5 // Set a mean global range1 = 3 global range2 = 15 // Set a range // Draw Poisson probability distribution functions twoway (function y=poissonp(\$mu,x) , range(0 \$range1) recast(area) ) /// || (function y=poissonp(\$mu,x) , range(0 \$range2) ), /// legend(off) ytitle("Probability P(x=count)") xtitle("Event Count") // Calculate probabilities forvalues i=0/\$range2 { di "Count `i'" di "p(x=`i'): " poissonp(\$mu,`i') // PDF (Probability Density Function) di "p(x<=`i'): " poisson(\$mu,`i') // CDF (Cumulative Density Function) di " " } clear all // clear memory global N = 1500 // the number of observations set seed 7654321 // Seed set obs \$N // Expand the number of observations gen x = 0 // Create a variable // Random number generation using Poisson probability distribution set more off forvalues j=1/\$N { replace x=rpoisson(\$mu) in `j' } // Draw a Poisson probability distribution function and histogram of x twoway (histogram x, bin(\$range2) ) /// || (function y=poissonp(\$mu,x) , range(0 \$range2) xlabel(0(1)\$range2) ) /// , legend(off) ytitle("Probability P(x=count)") xtitle("Event Count N=\$N") // End of this do file