#delimit; *=====================================================* PROGRAMACION ESTADISTICA EN EVALUACION DE IMPACTO ENERO 2012 *=====================================================* (Solucion desarrollada por Paloma Acevedo, Yyannu Cruz Aguayo y Conner Mullaly, si tiene preguntas y comentarios puede escribir a palomaa@iadb.org); clear; cap log close; set more off; set mem 20m; set matsize 200; program drop _all; *=========================*; gl data = "C:\Users\wb331358\Desktop\Chile_Jan2012\STATA\STATA_Chile"; gl logs = "C:\Users\wb331358\Desktop\Chile_Jan2012\STATA\STATA_Chile"; *========================*; log using "$logs\solution_log.txt", replace t; *============================* Macros *============================*; global variables1 ophe age_hh educ_hh age_sp educ_sp ethnicity_hh female_hh hhsize_basal dirtfloor_basal bathroom_basal landhectars_basal min_dist; global controls1 age_hh educ_hh age_sp educ_sp ethnicity_hh female_hh; global controls2 hhsize_basal dirtfloor_basal bathroom_basal landhectars_basal min_dist; *============================* SOLUCION PROGRAMA *============================*; use "$data\evaluation.dta"; *============================* CASE 0: ANTES Y DESPUES *============================*; *1; keep if treatcom==1; sum if round==0; *2; *Hay tres maneras de estimar la diferencia en medias: (a) calculando las medias y comparandolas, (b) haciendo un ttest, (c) mediante una regresion lineal; sum ophe if takeup==1 & round==0; sum ophe if takeup==1 & round==1; *. display 58.3121- 52.29373=6.01837; ttest ophe if takeup==1, by (round); *3; reg ophe round if takeup==1; reg ophe round if takeup==1, cl (local); *================================* CASO 1: AUTOSELECCIONADOS *================================*; *1; ttest ophe if round==0, by(takeup); ttest age_hh if round==0, by(takeup); ttest educ_hh if round==0, by(takeup); *o... comparandolos todos de una vez; foreach x of global variables1 {; describe `x'; ttest `x' if round==0, by(takeup); reg `x' takeup if round==0; }; *2; *i; reg ophe takeup if round==1; *ii; reg ophe takeup $controls1 if round==1; *3; *4; *==================================* CASO 2: DIFERENCIAS EN DIFERENCIAS *==================================*; *1; sort hhid round; gen delta_ophe= ophe-ophe[_n-1] if hhid==hhid[_n-1]; *2; ttest delta_ophe if round==1, by (takeup); *3; gen takeup_round = takeup*round; *i; reg delta_ophe takeup if round==1, cl(local); reg ophe takeup round takeup_round, cl (local); *ii; reg ophe takeup round takeup_round $controls1, cl (local); reg ophe takeup round takeup_round $controls1 $controls2, cl (local); *4; *5; *6 Chequeos de consistencia; preserve; use "$data\evaluation_extended.dta", clear; keep if treatcom==1; *twoway scatter ophe_med_t ophe_med_c round if round>=0; *twoway scatter ophe_med_t ophe_med_c round if round>=-1; twoway scatter ophe_med_t ophe_med_c round; *i; sort hhid round; gen delta_ophe= ophe-ophe[_n-1] if hhid==hhid[_n-1]; reg delta_ophe takeup if round==1, cl(local); reg delta_ophe takeup if round==1; ttest delta_ophe if round==1, by (takeup); ttest delta_ophe if round==0, by (takeup); ttest delta_ophe if round==-1, by (takeup); restore; *================================* CASE 3: REGRESION DISCONTINUA *================================*; *use "$data\evaluation.dta", clear; *keep if treatcom ==1; *br score eligible; *1; reg ophe eligible score if round==1; *2; *Plotting the predicted ophe against the score at baseline; reg ophe score if round==0; predict ophe_pred1; graph7 ophe_pred1 score if round==0; *Plotting the predicted values of ophe after the program; reg ophe eligible score if round==1; predict ophe_pred2; graph7 ophe_pred2 score if round==1; *3; reg ophe eligible if round==1; reg ophe eligible if round==1 & score>=500 & score <=1000; *4; reg ophe eligible if round==1 & score>=600 & score <=900; reg ophe eligible if round==1 & score>=700 & score <=800; reg ophe eligible if round==1 & score>=725 & score <=775; reg ophe eligible $controls1 $controls2 if round==1 & score>=725 & score <=775; *======================================* CASE 4: VARIABLES INSTRUMENTALES *======================================*; use "$data\evaluation.dta", clear; *1; *i; ivreg ophe (takeup = treatcom) if round ==1 & eligible ==1; *ii; ivreg ophe (takeup = treatcom) $controls1 if round ==1 & eligible ==1; *iii; ivreg ophe (takeup = treatcom) $controls1 $controls2 if round ==1 & eligible ==1; *================================* CASE 5: MATCHING *================================*; use "$data\evaluation.dta", clear; keep if round ==1 & treatcom ==1; *1. Probability of participating; logit takeup $controls1; predict pscore; kdensity pscore if takeup ==1, gen(take1 den1); kdensity pscore if takeup ==0, gen(take0 den0); twoway (line den0 take0) (line den1 take1); *2. Generate quintiles; xtile prob_tile = pscore, nq(5); *3. Average comparison; foreach x of varlist age_hh educ_hh age_sp educ_sp ethnicity_hh female_hh {; foreach y of numlist 1/5 {; ttest `x' if prob_tile ==`y', by(takeup); }; }; *4. OLS in the balanced quintiles; *(i) Without controls; reg ophe takeup if prob_tile >=2 & prob_tile <=4; *(ii) Including pscore as a control; reg ophe takeup pscore if prob_tile >=2 & prob_tile <=4; *5. Use psmatch2 command * (i) let it calculate propensity score using controls; psmatch2 takeup $controls1 $controls2, out(ophe); * (i) use already obtained propensity score, without imposing common support; psmatch2 takeup, out(ophe) pscore (pscore); * (i) use already obtained propensity score, imposing common support; psmatch2 takeup, out(ophe) pscore (pscore) com; * (i) use already obtained propensity score, imposing common support, kernel; psmatch2 takeup, out(ophe) pscore (pscore) kernel com; *5. age2, age3, educ2, educ3, hhsize2, hhsize3; *================================* CASE 6: ALEATORIZACION *================================*; use "$data\evaluation.dta", clear; tab eligible treatcom if round==0; *1; foreach x of global variables1 {; describe `x'; ttest `x' if round==0 & eligible, by(treatcom); }; *2; ttest ophe if round==1 & eligible==1, by (treatcom); *3; *i; reg ophe treatcom if round==1 & eligible==1; *ii; reg ophe treatcom $controls1 if round==1 & eligible==1; *iii; reg ophe treatcom $controls1 $controls2 if round==1 & eligible==1;