Logo Studenta

lalonde_matching

Esta es una vista previa del archivo. Inicie sesión para ver el archivo original

clear all 
set more off 
set dp comma
**********************************************************
*Title: Ayudantía Matching *
* Economía y Evaluación de Políticas Sociales *
*Author: Katiza Mitrovic *
*Mail: kmitrovic@uc.cl *
*University: Instituto de Economía *
* Pontificia Universidad Católica de Chile *
*Date: 29 Nov. 2019 *
*Version: Stata/MP 15.0 *
**********************************************************
*set path and load data:
cd "C:\Users\ktz\Documents\UC Comercial\ULTIMO SEM\EEPS\Ayudantía Matching"
use lalonde12
*a) Balance en observables pre tratamiento
{
*Obtenemos las características promedio para los individuos tratados y controles por separado. 
tabstat age school black hispanic married, by(treatment)
tabstat re74 re75 u75 u74, by(treatment)
*Analizamos si las diferencias son significativas 
ttest age, by(treatment)
ttest school, by(treatment)
ttest black, by(treatment)
ttest hispanic, by(treatment)
ttest married, by(treatment)
ttest re74, by(treatment)
ttest re75, by(treatment)
ttest u74, by(treatment)
ttest u75, by(treatment)
*Estimamos pscore
dprobit treatment age school black hispanic married re74 re75 u75 u74
*Predecimos el p-score para cada observación
predict pscore 
*c)Soporte Común
*Graficamente 
histogram pscore, by(treatment) 
*Graficos más bonitos
ssc install grstyle
grstyle init
grstyle color background white // set overall background to white
histogram pscore, by(treatment) 
*Podemos imponer la restricción de usar solo las observaciones que están en el soporte común
gen pscore_sc=pscore
*Encontramos la máxima probabilidad predicha para el grupo de control:
sum pscore_sc if treatment==0
scalar max_control=r(max)
*Encontramos la mínima probabilidad predicha para el grupo de tratamiento:
sum pscore_sc if treatment==1
scalar min_treat=r(min)
replace pscore_sc=. if treatment==1 & pscore_sc>max_control
replace pscore_sc=. if treatment==0 & pscore_sc<min_treat
*Vemos cuantas observaciones perdemos al imponer esta restricciÛn:
count if pscore!=. & pscore_sc==.
}
*d)Estimación por matching 
{
* Instalamos comando para hacer matching 
ssc install psmatch2, replace
ssc install nnmatch
*** Matching en características ***
* Nearest Neighbour matching en caracteristicas con 1 vecino
teffects nnmatch (re78 age school black hispanic married re74 re75 u75 u74) (treatment), nn(1) m(ivar)
estimates store nn1, title("NN 1 vecino")
* Nearest Neighbour matching en caracteristicas con 2 vecino
teffects nnmatch (re78 age school black hispanic married re74 re75 u75 u74) (treatment), nn(2) m(ivar)
estimates store nn2, title("NN 2 vecinos")
*** Matching en Propensity Score ***
*usando comando viejo
*psmatch2 by default reports the average treatment effect on the treated (which it refers to as ATT)
*uses a probit model for the probability of treatment
psmatch2 treatment age school black hispanic married re74 re75 u75 u74, outcome(re78) n(1) com
estimates store ps1, title("PS psmatch2")
* Si se viola el supuesto de sobreposición en observaciones, no se puede usar comando teffects
*usando comando nuevo
*reports the average treatment effect (ATE)
*but will calculate the average treatment effect on the treated (which it refers to as ATET) if given the atet option
*uses a logit model by default, but will use probit if the probit option is applied to the treatment equation
teffects psmatch (re78) (treatment age school black hispanic married re74 re75 u75 u74, probit), atet
estimates store ps2, title("PS teffects ATET")
teffects psmatch (re78) (treatment age school black hispanic married re74 re75 u75 u74), osample(violasupuesto)
estimates store ps3, title("PS teffects ATE")
*volver a correr desde aca:
drop if violasupuesto==1
teffects psmatch (re78) (treatment age school black hispanic married re74 re75 u75 u74)
estimates store ps3, title("PS teffects ATE")
*Ponermos en una tabla y comparamos distintas estimaciones
estout nn1 nn2 ps1 ps2 ps3, title("Comparing treatment effects") cells(b(star fmt(2)) se(par fmt(2))) label stats(N, fmt(0) label(N))
}
******************************* THE END ****************************************

Continuar navegando