program define chisq version 4.0 preserve clear quietly { set obs 501 gen x = . gen y = .} global df=10 wdctl button "Reset" 15 5 25 12 HJN_B0 wdctl button "df +" 15 20 25 12 HJN_B1 wdctl button "df -" 15 35 25 12 HJN_B2 wdctl button "Help" 15 50 25 12 HJN_B5 wdctl button "Close" 15 65 25 12 HJN_B6 global D_sm1 "Inc" global dfinc=10 wdctl static D_sm1 3 110 10 10 wdctl edit dfinc 15 110 25 10 global D_sm2 "df:" wdctl static D_sm2 15 125 15 12 wdctl static df 35 125 15 12 global HJN_B0 "chisqdr 0" global HJN_B1 "chisqdr 1" global HJN_B2 "chisqdr -1" global HJN_B5 "whelp chisq" global HJN_B6 "exit 1234" gph open chisqdr 0 noi wdlg "Chi-square Curves" 5 5 80 165 gph close restore end program define chisqdr version 4.0 local arg=`1' if `arg'!=0 { graph y x, xlab(0,25,50,75,100,125,150) ylab(0,.025,.050,.075,.100) xscale(0,150) yscale(0,.1) c(l) s(i) l1(" ") l2(" ") b1(" ") b2(" ") pen(3)} if `arg'==0 { global df=10 gph close gph open} if `arg'==1 { global df = min(100,$df+$dfinc)} if `arg'==-1 { global df = max(10,$df-$dfinc)} local xmin=invnchi($df,0,.001) local xmax=min(invnchi($df,0,.999),150) replace x=`xmin'+(`xmax'-`xmin')*(_n-1)/(_N-1) pdf_chi2 x y $df graph y x, xlab(0,25,50,75,100,125,150) ylab(0,.025,.050,.075,.100) xscale(0,150) yscale(0,.1) c(l) s(i) l1(" ") l2(" ") b1(" ") b2(" ") pen(2) gphconv summarize y local yy=_result(6)+.001 local xx=$df-1 drtext `xx' `yy' 0 "$df" end exit