program define tryhist version 4.0 preserve clear gph open gph pen 1 set obs 500 gen y = 100+15*invnorm(uniform()) replace y = max(y,55) replace y = min(y,145) gen x = 55+90*(_n-1)/(_N-1) gen fx = exp(-((x-100)^2)/(2*225))/sqrt(2*_pi*225) graph fx x, c(l) s(i) xlab(55,70,85,100,115,130,145) ylab(0,.01,.02,.03) l1(" ") l2(" ") b1(" ") b2(" ") gphconv histgm y 55 145 20 gph close end program define histgm version 4.0 local y = "`1'" local xmin = `2' local xmax = `3' local nbins = `4' local del = (`xmax'-`xmin')/`nbins' tempvar x1 x2 y1 y2 gen `x1' = `xmin' + (_n)*`del' in 1/`nbins' gen `y1'=. gen `y2'=. gen `x2'=. replace `y1' = int(`nbins'* (`y'-`xmin')/(`xmax'-`xmin'))+1 replace `y1'=min(`y1',`nbins') replace `y1'=max(`y1',1) local i = 1 while `i' <= `nbins' { count if `y1'==`i' replace `y2' = _result(1) in `i' local i=`i'+1} replace `y2' = `y2'/((_N)*`del') replace `y1' = 0 replace `x2' = `x1'-`del' * gph text 6000 16000 0 0 After replaces segments `x1' `y1' `x1' `y2' segments `x2' `y1' `x2' `y2' segments `x1' `y2' `x2' `y2' segments `x1' `y1' `x2' `y1' gph clear 1000 24000 2000 30000 end