Dec 5, 2025

Comparing margins from OLS and IV models

webuse hsng2, clear

sum hsngval // Get avg. and SD

// OLS
regress rent pcturban hsngval faminc i.region 
margins, at(hsngval = (32714 48484 64254)) saving(ols, replace)

// IV
ivregress 2sls rent pcturban (hsngval = faminc i.region)
margins, at(hsngval = (32714 48484 64254)) saving(iv, replace)

// Plot
combomarginsplot ols iv, labels("OLS" "IV") ///
                         title("{bf:A}", span bexpand justification(left)) ///
                         xtitle(Median housing value) ///
                         ytitle(Median gross rent) ///
                         xlabel(48484 "Avg." 64254 "+1 SD" 32714 "-1 SD") ///
                         recastci(rarea) ciopt(color(%30) lcolor(white)) ///
                         legend(pos(11) ring(0)) ///
                         scheme(lean1) name(ols_iv_predictions, replace)