########## Binary Models ##################### Linear Probability Model use "C:\Users\Luigi\Dropbox\Corsi 2014\Multivariate PHD 2014\logit\school.dta", clear twoway (scatter hiqual avg_ed) (lfit hiqual avg_ed) regress hiqual avg_ed lincom _b[_cons]+_b[avg_ed]*3 margins, at(avg_ed=3) predict yhat twoway scatter yhat hiqual avg_ed #################### Probit Model probit hiqual avg_ed margins, at(avg_ed=3) marginsplot # estimating the linear prediction (not the probability!) margins, at(avg_ed=3) predict(xb) probit hiqual avg_ed predict yhat1 twoway scatter yhat1 hiqual avg_ed, sort ylabel(0 1) margins, at(avg_ed=(1 (0.1) 5)) marginsplot marginsplot, yline(0) probit hiqual avg_ed margins, at(avg_ed=(2 3 4)) marginsplot, yline(0) probit hiqual avg_ed margins, at(avg_ed=(2 3)) contrast(atcontrast(r._at) wald) margins, at(avg_ed=(3 4)) contrast(atcontrast(r._at) wald) #################### Logit Model logit hiqual avg_ed di 1/(1+exp(-( -12.30054 +3*3.909635 ))) di exp( -12.30054 +3*3.909635 )/(1+exp( -12.30054 +3*3.909635 )) margins, at(avg_ed=3) logit hiqual avg_ed predict yhat2 twoway scatter yhat2 hiqual avg_ed, ylabel(0 1) ### Comparing probit and logit model corr yhat1 yhat2 twoway (scatter yhat1 hiqual avg_ed, ylabel(0 1)) /// (scatter yhat2 hiqual avg_ed, ylabel(0 1)), legend(order(1 "Logit" 3 "Probit")) ### odds logit hiqual avg_ed di exp( 3.909635 ) logit hiqual avg_ed, or logistic hiqual avg_ed ################## Turnout Model use "C:\Users\Luigi\Dropbox\Corsi 2014\Multivariate PHD 2014\logit\nes2004.dta", clear logit vote_2004 educ predict yhat tab educ, sum(yhat) nost # Assessing goodness of fit ##### Likelihood ratio di -2*(-553.07398- - 509.37393) logit vote_2004 educ est store full_model logit vote_2004 if e(sample) lrtest full_model . #### McFadden Pseudo R^2 di (-553.07398 - -509.37393)/(-553.07398) ### fraction correctly predicted logit vote_2004 educ estat classification di (821+19)/1065 di 821/837 di 19/228 ### Hosmer and Lemeshow's test estat gof, table table educ if vote_2004!=. estat gof, group(4) table ### Multiple IV logit vote_2004 educ logit vote_2004 educ age ### Comparing models: the likelihood ratio test * full model logit vote_2004 educ age est store full_model * with age removed from the model logit vote_2004 educ if e(sample) lrtest full_model . ### another example with more comparisons * full model logit vote_2004 educ age income_hh est store a * with income_hh removed from the model logit vote_2004 educ age if e(sample) est store b lrtest a b, stats * with income_hh and age removed from the full model logit vote_2004 educ if e(sample) est store c lrtest a c lrtest b c ### a multivariate model with a probit use "C:\Users\Luigi\Dropbox\Corsi 2014\Multivariate PHD 2014\logit\school.dta", clear probit hiqual avg_ed enroll meals margins, at(avg_ed=(2 3 4) (mean)_all) margins, at(avg_ed=(2 3 4) meals=2 (mean)_all) margins, at(avg_ed=(2 3 4) meals=12 (mean)_all) margins, at(avg_ed=(2 3 4) meals=(2 12 22 32) (mean)_all) marginsplot # Be careful with margins when using a non-linear model! probit hiqual avg_ed enroll meals margins, at(avg_ed=(2 3 4) (mean)_all) margins, at(avg_ed=(2 3 4)) list hiqual avg_ed enroll meals in 1/2 reg hiqual avg_ed enroll meals margins, at(avg_ed=(2 3 4) (mean)_all) margins, at(avg_ed=(2 3 4)) ### Useful command to download ### Fitstat # findit fitstat use "C:\Users\Luigi\Dropbox\Corsi 2014\Multivariate PHD 2014\logit\nes2004.dta", clear logit vote_2004 educ age fitstat # Comparing nested models with fitstat logit vote_2004 educ age income_hh fitstat, saving(m1) logit vote_2004 educ age if e(sample) fitstat, using(m1) ################ # Testing directly a quadratic relationship ################ use "C:\Users\Luigi\Dropbox\Corsi 2014\Multivariate PHD 2014\logit\school.dta", clear probit hiqual avg_ed enroll c.meals##c.meals # predicted DV (PR Y=1) at different values of meals from 0 to 100 sum meals margins, at(meals=(0 (10) 100)) marginsplot # marginal impact of increasing meals by 1 unit probit hiqual avg_ed enroll c.meals##c.meals margins, dydx(meals) at(meals=(0 (10) 100)) marginsplot, yline(0) # compare with marginal impact of increasing meals by 1 unit without quadratic term probit hiqual avg_ed enroll meals margins, dydx(meals) at(meals=(0 (10) 100)) marginsplot, yline(0) ################ # Testing directly an interaction ################ * test the interacion between avg_ed and meals, while controlling for enroll