program define scatt2 version 4.0 preserve clear global np=0 quietly{ set obs 600 gen x=. gen y=.} global D_sm11 " This lab lets you experiment with different values of n and rho. Every time you click on Run you get a new scatterplot. You can try out different values of rho and n and see what effect they have. Note that you can keep the graphics window in the front and still be able to change rho and n and click on Run." wdctl static D_sm11 5 5 270 40 global D_sm12 "Things to Notice: 1) Positive (negative) values of rho mean the points fall close to a line having positive (negative) slope, 2) The closer rho is to +1 or -1, the closer the points are to the line. 3) For values of rho between about -.4 to +.4, the scatterplots look very similar unless n is quite large." wdctl static D_sm12 5 50 270 40 global HJN_V1 = 100 global HJN_1 "n" wdctl static HJN_1 5 92 10 8 wdctl edit HJN_V1 20 92 20 8 global HJN_V2 = 0 global HJN_2 "Rho" wdctl static HJN_2 50 92 20 8 wdctl edit HJN_V2 75 92 20 8 wdctl button "Run" 125 90 25 12 HJN_B2 wdctl button "Close" 155 90 25 12 HJN_B3 wdctl button "Help" 185 90 25 12 HJN_B4 global HJN_B2 "scatt2dr" global HJN_B4 "whelp scatt2" global HJN_B3 "exit 1234" gph open gph pen 1 scatt2dr global HJN_V2=.9 scatt2dr global HJN_V2=-.9 scatt2dr global HJN_V2=.99 scatt2dr noi wdlg "Scatterplots, II" 5 150 280 120 gph close restore end program define scatt2dr version 4.0 local n=$HJN_V1 local rho=$HJN_V2 if `n' < 2 | `n' > 600 { sstopbox stop "sample size must be between 2 and 600" exit} if `rho' <= -1 | `rho' >= 1 { sstopbox stop "rho must be between -1 and 1" exit} global np=$np+1 * gph text 500 5000 0 0 `n' `rho' $np local np1=$np if `np1'==5 { gph close gph open gph pen 1 global np=1 local np1=1} * gph text 2000 5000 0 0 `np1' local nx1=int((`np1'-1)/2)*15000 local nx2=`nx1'+15000 local ny1=mod(`np1'-1,2)*11000 local ny2=`ny1'+11000 local nx=int((`nx1'+`nx2')/2) local ny=`ny1'+500 * gph text 3000 5000 0 0 `nx1' `nx1' `ny1' `ny2' `nx' `ny' replace x=. replace y=. replace x = invnorm(uniform()) in 1/`n' replace y = `rho'*x + sqrt(1.0-`rho'*`rho')*invnorm(uniform()) in 1/`n' graph y x, xlab(-3,0,3) ylab(-3,0,3) xscale(-3,3) s(o) /* */ yscale(-3,3) bbox(`ny1',`nx1',`ny2',`nx2',850,400,0) local mrho: display %4.2f `rho' gph text `ny' `nx' 0 0 rho = `mrho' end exit