capture log close log using "SOCY699C-HW4-REGRESS-POSTESTIMATE.txt", text replace /* Regression postestimation examples */ capture drop id gen id=_n if e(sample) label variable id "Respondent ID" regress sexfrq i.sex i.race age educ year i.marital attend1 reliten1 predict yhat if e(sample), xb predict e if e(sample), residuals predict rstd if e(sample), rstandard /* Visual check for heterscedasticity */ #delimit ; graph twoway (scatter e id, msize(tiny)), title("Heterscedasticity") name(reg_hetero, replace); #delimit cr /* Visual check for outliers */ #delimit ; graph twoway (scatter rstd id, msize(tiny)), title("Outliers") yline(-1.96 1.96, lw(thick) lp(dash)) name(reg_out, replace); #delimit cr /* Added variable plot for age */ #delimit ; avplot age, msize(tiny) rlopts(lw(medthick) lc(maroon)) name(avplot_sexfreq, replace); #delimit cr quietly regress sexfrq i.sex i.race age educ year i.marital attend1 reliten1 if year==2008 avplots, msize(tiny) name(avplots_sexfreq, replace) /* Clean up the examples */ capture drop id yhat e rstd /* Regression postestimation problems */ regress sociability i.sex i.race age educ year i.marital attend1 reliten1 gen id=_n if e(sample) predict rstd if e(sample), rstandard #delimit ; graph twoway (scatter rstd id, msize(tiny)), title("Outliers") yline(-1.96 1.96, lw(thick) lp(dash)) name(reg_out, replace); #delimit cr #delimit ; graph twoway (scatter rstd id, msize(tiny)) (scatter rstd id if rstd<-1.96 | rstd>1.96, msize(tiny)), title("Outliers") yline(-1.96 1.96, lw(thick) lp(dash)) name(reg_out, replace); #delimit cr #delimit ; graph twoway (scatter rstd id if (rstd>-1.96 & rstd<1.96) & year==2006, msize(tiny)) (scatter rstd id if (rstd<-1.96 | rstd>1.96) & year==2006, m(i) mlabel(id) mlabsize(vsmall) mlabposition(0)), title("Outliers") yline(-1.96 1.96, lw(thick) lp(dash)) legend(off) name(reg_out1, replace); #delimit cr capture drop id rstd /* Breusch-Pagan/Cook-Weisberg test and VIFs */ estat hettest estat vif /* avplots */ avplot age, msize(tiny) name(avplot_soc, replace) quietly regress sociability i.sex i.race age educ year i.marital attend1 reliten1 if year==2008 avplots, msize(tiny) name(avplots_soc, replace) log close