  # st: graphing normally distributed variables

 From "victor michael zammit" To Subject st: graphing normally distributed variables Date Wed, 30 Jul 2003 00:42:39 +0200

```Dear Statalist,
What I am trying to do here,is to take any normally distributed variable
,that is to say ,with any mean and standard deviation ,and disect it into 50
equal intervals (bins) ,and then compare the two distributions.I would
appreciate any comments on how this could be done differently :

capture program drop bins
program define bins
local q = `1' - (4* `2')
local r = `1' + (4* `2')
local s = `r' - `q'
local t = `s'/50
local u = `q' + `t'
local v = `r'- `t'
local y = 1
clear
set obs 10000
gen b = .
gen a = `1' + `2' * invnorm(uniform())
while `q'<= `v'  {
while `u'<= `r' {
while `y'<= 50  {
count if a > `q' & a<= `u'
replace b = r(N) in `y'
local q = `q' + `t'
local u = `u' + `t'
local y = `y' + 1
}
}
}
gen ab = _n
save bins`3',replace
graph a, bin(50)
graph b ab , connect(ll)
end
bins 1232  456 1
bins 5643 289 2
bins 34 8 3
bins 0 1 4
bins -786 231 5

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```