*! version 1.0.0 STB-34 gr20 program define tryrej version 5.0 quietly { preserve clear gph open, saving(tryrej1.gph,replace) set obs 201 gen x=5*(_n-101)/100 gen y=sqrt(_pi/2)*exp(-x^2/2)*(1+x^2) graph y x, c(l) s(i) xlab(-5,-4,-3,-2,-1,0,1,2,3,4,5) ylab /* */ title("N(0,1)/Standard Cauchy") gphsave local c=sqrt(2*_pi)*exp(-.5) local dc: display %5.3f `c' local oc: display %5.3f 1-(1/`c') gphdt line `c' -1 0 -1 gphdt line `c' 1 0 1 gphdt line 0 -5 0 5 gphdt text `c' 1 0 -1 (1,`dc') gphdt text `c' -1 0 1 (-1,`dc') gph close gph open, saving(tryrej2.gph,replace) * Graph h(x)=c*g(x): gen h=`c'/(_pi*(1+x^2)) graph h x, c(l) s(i) xlab(-5,-4,-3,-2,-1,0,1,2,3,4,5) ylab /* */ title("h(x) and f(x), P(rejection = `oc'") gphsave * Add N(0,1) curve and shade rejection region: replace y=exp(-x^2/2)/sqrt(2*_pi) gphdt vline y x gphdt vpoly y x h x gph close } end