cd "C:\Users\sovid\OneDrive - The University of Kansas\Lectures\Soc910_AdvStat\examples" use soc910_data_EASS2012.dta, clear gen yrsch = educyrs replace yrsch = . if educyrs==88 * ----- * OLS * ----- reg SWB heterophily R_age Female yrsch Employed SSS i.v2 [pw=weight] * ----- * IPW * ----- teffects ipw (SWB) (heterophily R_age Female yrsch Employed SSS i.v2, logit) [pw=weight] * ----- * IPW: step-by-step * ----- * Step 1: Estimate Logit logit heterophily R_age Female yrsch Employed SSS i.v2 [pw=weight] * Step 2: Estimate the predicted prob predict P * Step 3: Compute IPW values gen IPW=1/P if heterophily==1 replace IPW=1/(1-P) if heterophily==0 gen newIPW = weight * IPW * Step 4: Estimate OLS with new weight reg SWB heterophily [pw=newwt] * ----- * testing balance between heterophily = 1 and heterophily = 0 * ----- tab v2, gen(ctry) tabstat R_age Female yrsch Employed SSS ctry1-ctry4 [aw=weight], by(heterophily) tabstat R_age Female yrsch Employed SSS ctry1-ctry4 [aw=newIPW], by(heterophily) reg R_age heterophily [pw=weight] reg R_age heterophily [pw=newIPW] reg SSS heterophily [pw=weight] reg SSS heterophily [pw=newIPW] foreach i of var R_age Female yrsch Employed SSS ctry1-ctry4 { reg `i' heterophily [pw=newIPW] }