/* logistic regression */ use http://www.ats.ucla.edu/stat/stata/notes/hsb2, clear generate hiwrite = write>=52 describe hiwrite read female prog summarize hiwrite read female prog tab1 hiwrite female prog xi: logit hiwrite read female i.prog estimates store M1 /* Wald test */ test _Iprog_2 _Iprog_3 /* Likelihood ratio-test */ logit hiwrite read female, nolog lrtest M1 /* rerun full model */ xi: logit hiwrite read female i.prog, nolog /* displays coefficients */ xi: logistic hiwrite read female i.prog, nolog /* displays odds ratios */ /* long & freeze */ listcoef listcoef, percent fitstat lfit, group(10) /* diagnostics */ predict pprob /* predicted probabilities */ predict r, resid /* pearson residulas */ predict h, hat /* leverage*/ predict db, dbeta /* pregobon dbeta */ predict dx2, dx2 /* hosmer & lemeshow influence */ scatter h r, xline(0) msym(Oh) jitter(2) twoway (scatter dx2 pprob if hiwrite, msym(Oh) jitter(2)) /// (scatter dx2 pprob if ~hiwrite, msym(Oh) jitter(2)) scatter dx2 pprob if hiwrite [w=db], msym(Oh) jitter(2) /* predicted probabilities */ summarize pprob histogram pprob list hiwrite pprob in 1/30 leastlikely hiwrite read female prog /* from Freese - not part of spostado */ prchange prchange, fromto prchange, x(_Iprog_2=0 _Iprog_3=0) prchange, x(_Iprog_2=1 _Iprog_3=0) prchange, x(_Iprog_2=0 _Iprog_3=1) prvalue, x(female=0 _Iprog_2=1 _Iprog_3=0) rest(mean) prtab read prtab read female prtab read female, x(_Iprog_2=1 _Iprog_3=0) prgen read, from(0) to(100) gen(prg1) x(_Iprog_2=0 _Iprog_3=0 female=1) n(11) prgen read, from(0) to(100) gen(prg2) x(_Iprog_2=1 _Iprog_3=0 female=1) n(11) prgen read, from(0) to(100) gen(prg3) x(_Iprog_2=0 _Iprog_3=1 female=1) n(11) graph twoway scatter prg1p1 prg2p1 prg3p1 prg1x, con(l l l) msym(O D S) /* using xi3 & postgr3 */ xi3: logit hiwrite read female i.prog postgr3 read, by(prog) x(female=1) /* demonstrate xi3 again using ses */ xi: logit hiwrite i.ses test _Ises_2 _Ises_3 xi3: logit hiwrite o.ses describe _Ises_1 _Ises_2 test _Ises_1 _Ises_2 /* categorical predictors */ xi3: logit hiwrite g.prog*g.female test _Iprog_2 _Iprog_3 test _Ipr2Xfe1 _Ipr3Xfe1 postgr3 prog, by(female) xi3: logit hiwrite g.prog*g.female read test _Iprog_2 _Iprog_3 test _Ipr2Xfe1 _Ipr3Xfe1 postgr3 prog, by(female) postgr3 prog, by(female) x(read=42) postgr3 prog, by(female) x(read=62)