program drop _all program define sim, rclass drop _all set obs 25 gen x1 = rnormal() gen x2 = rnormal() gen x3 = rnormal() gen y = runiform() < invlogit(-2 + x1) logit y x1 x2 x3 test x2=x3=0 return scalar p = r(p) return scalar chi2 = r(chi2) end set seed 123456 // this will take a while. If you want some // entertainment or an idea how far the // simulation has progressed, remove the // nodots option simulate chi2 = r(chi2) p=r(p), reps(1000) nodots : sim hangroot chi2, dist(chi2) par(2) name(chi, replace) /// title("distribution of Wald statistics" /// "compared to a {&chi}{sup:2}(2) distribution" ) /// xtitle(Wald statistics) /// ytitle("frequency (log scale)") /// ylab(-2 "-4" 0 "0" 2 "4" 4 "16" 6 "36" 8 "64") hangroot p , dist(uniform) par(0 1) /// susp notheor ci name(p, replace) /// title("deviations of the distribution of p-values" /// "from the uniform distribution") /// xtitle("p-value") ytitle("residual (log scale)") /// ylab(-4 "-16" -3 "-9" -2 "-4" -1 "-1" 0 "0" 1 "1" )