Probability distributions

| Gabriel |

I wrote this little demo for my stats class to show how normal distributions result from complex processes that sum the constituent parts whereas count distributions result from complex processes where a single constituent failure is catastrophic.

*this do-file is a simple demo of how you statistical distributions are built up from additive vs sudden-death causation
*this is entirely based on a simulated coin toss -- the function &quot;round(uniform())&quot;
*one either counts how many heads out of 10 tosses or how long a streak of heads lasts
*I'm building up from this simple function for pedagogical purposes, in actual programming there are much more direct functions like rnormal()

*1. The normal distribution
clear
set obs 1000
forvalues var=1/10 {
quietly gen xvar'=.
}
forvalues row=1/1000 {
forvalues var=1/10 {
quietly replace xvar'=round(uniform()) in row'
}
}

*show five examples
list in 1/5

*2. Count distribution
*Failure is catastrophic
clear
set obs 1000
forvalues var=1/30 {
quietly gen xvar'=.
}
gen streak=0
lab var streak &quot;consecutive heads before first tails&quot;
gen fail=0
forvalues row=1/1000 {
forvalues var=1/30 {
quietly replace xvar'=round(uniform()) in row'
quietly replace fail=1 if xvar'==0
quietly replace streak=var' if fail==0
}
quietly replace fail=. in row'/row'
}
quietly replace streak=0 if x1==0

*show five partial examples
list streak x1 x2 x3 x4 x5 in 1/5
histogram streak, discrete
*have a nice day