program define disc version 4.0 preserve /* Save all the current stata stuff */ clear /* Clear everything so no conflicts */ quietly{ set obs 501 gen x=. gen y=. gen x1=. gen x2=. gen zero=0} global D_sm11 " This lab graphically illustrates the idea of critical value(s) for confidence intervals and tests of hypotheses using the Z, t, chi-square, and F distributions." wdctl static D_sm11 5 5 290 15 global D_sm12 " You specify 1) which distribution to study, 2) what type of test to study (two-sided, left-sided, or right-sided), 3) which of four alpha's to use, and 4) what degrees of freedom to use (for t and chi-square) or numerator and denominator degrees of freedom to use (for F). When you then click on Run, the graph of the chosen distribution is placed on the screen with areas under the curve specified by alpha shaded in and the critical value(s) written next to the shaded areas." wdctl static D_sm12 5 25 290 50 global D_sm13 " Suggestions: 1) run the lab several times varying only alpha and note what happens to the shaded areas and critical values, 2) run the lab for the t, increasing the degrees of freedom each time." wdctl static D_sm13 5 75 290 35 global D_sm1 "n" global HJN_V1=20 wdctl static D_sm1 5 120 15 10 wdctl edit HJN_V1 25 120 20 10 global D_sm3 "Experiment" global D_sm4 "Binomial%Hypergeometric%Negative Binomial" wdctl static D_sm3 120 110 20 10 global D_var3 "Binomial" wdctl ssimple D_var3 D_sm4 120 120 50 60 parse(%) global D_sm6 "Pop. Size" global D_sm7 "50 100 200 500" wdctl static D_sm6 190 110 20 10 global D_var1 "50" wdctl ssimple D_var1 D_sm7 190 120 30 60 global D_sm8 "Prop. of 1's" global D_sm9 ".02 .10 .25 .50 .75 .90 .98" wdctl static D_sm8 230 110 45 10 global D_var2 ".50" wdctl ssimple D_var2 D_sm9 230 120 55 60 wdctl button "Run" 5 160 30 14 D_b1 wdctl button "Close" 40 160 30 14 D_b2 wdctl button "Help" 75 160 30 14 D_b3 help global D_b1 "discdr" global D_b2 "exit 1234" global D_b3 "whelp disc" cap noi wdlg "Sampling With and Without Replacement" $D_dlgx $D_dlgy 300 240 restore end program define discdr version 4.0 gph open gph pen 1 local n = $HJN_V1 local npop = $D_var1 local p = $D_var2 if "$D_var3"=="Binomial" { replace x=. replace y=. local nobs= `n'+1 replace x = _n-1 in 1/`nobs' replace y = exp(lngamma(`n'+1)-lngamma(x+1)-lngamma(`n'-x+1)+x*log(`p') + (`n'-x)*log(1-`p')) local np1=`n'+1 graph y x, s(i) xlab(-1,`np1') ylab l1(" ") l2(" ") b1(" ") b2(" ") /* */ bbox(3500,0,23000,32000,850,400,0) gphconv replace x1=x-.5 replace x2=x+.5 replace zero=0 segments x1 zero x1 y segments x2 zero x2 y segments x1 y x2 y segments x1 zero x2 zero local np=int(`n'*`p'+1) local yy=y[`np'] local yy1=-`yy'/10. local yy2=1.5*`yy1' local i=0 while `i' <= `n' { if 2*int(`i'/2)==`i' {drtext `i' `yy1' 0 `i'} else {drtext `i' `yy2' 0 `i'} local ip1=`i'+1 local yip1: display %4.3f y[`ip1'] local yip11=`yip1'+.01 if `yip1' > .01 {drtext `i' `yip11' 0 `yip1'} local i = `i'+1} exit} sstopbox stop "This lab needs more work" exit gph close end exit