tekst3

****Random
gen lexptot=ln(1+exptot)
gen lnland=ln(1+hhland/100)
ttest  lexptot, by (dfmfd)
ttest  lexptot, by (dmmfd)

****DID
***Manually;
use ..\data\hh_9198;
gen exptot0=exptot if year==0
egen exptot91=max(exptot0), by(nh)
keep if year==1
gen lexptot91=ln(1+exptot91) if year==1
gen lexptot98=ln(1+exptot) if year==1
gen lexptot9891=lexptot98-lexptot91
ttest lexptot9891 if year==1, by(dfmfd)

ttest lexptot9891 if year==1, by(dmmfd)


***Regression implementation;
gen lexptot=ln(1+exptot)
gen lnland=ln(1+hhland/100)

gen dfmfd1=dfmfd==1 & year==1
egen dfmfd98=max(dfmfd1), by(nh)
gen dfmfdyr=dfmfd98*year
reg lexptot year dfmfd98 dfmfdyr
reg lexptot year dfmfd98 dfmfdyr sexhead agehead educhead lnland vaccess pcirr rice wheat milk oil egg 

****Fixed effects: Basic;
xtreg lexptot year dfmfd98 dfmfdyr, fe i(nh)


****PSM;
gen lnland= ln(1+ hhland/100)
gen lexptot=ln(1+exptot)

pscore dfmfd sexhead agehead educhead lnland vaccess pcirr rice wheat milk oil egg [pw=weight], pscore(ps98) blockid(blockf1) comsup level(0.001)

****Nearest Neighbor Matching;
attnd lexptot dfmfd [pweight=weight], pscore(ps98) comsup

****Stratification Matching;
atts lexptot dfmfd, pscore(ps98) blockid(blockf1) comsup

****Radius Matching;
attr lexptot dfmfd, pscore(ps98) radius(0.001) comsup

****Kernel Matching;
attk lexptot dfmfd, pscore(ps98) comsup bootstrap reps(50)

***CSC;
table dfmfd, c(sum ps98 min ps98 max ps98)
su ps98 if  dfmfd==1
gen comsup2=(ps98>=r(min))
su ps98 if  dfmfd==0
replace comsup2=0 if ps98>=r(max)


*RDD;
egen age_bins = cut(age), at(46(0.25)54)
tab age_bins
su age_bins

bysort age_bins: egen mean_unempdur = mean(unemployment_duration)

**Assumption of a quadratic relationship between unemployment duration and age

scatter mean_unempdur age_bins  || qfit mean_unempdur age_bins if age_bins < 50 ///
|| qfit mean_unempdur age_bins if age_bins >= 50 , xlabel(46(1)54) ylabel(0(10)40) xline(50)

*create the treatment dummy:
gen t=(age >=50)
tab t

* Estimate a local polinomial regressions:
cap drop output*
lpoly unemployment_duration age if age<50, degree(3) kernel(epan2) generate(output0) at(age) nograph
lpoly unemployment_duration age if age>=50, degree(3) kernel(epan2) generate(output1) at(age) nograph 

sum output0 if age>=49 & age <50
scalar outcome0 =r(mean)

sum output1 if age>=50 & age<51
scalar outcome1 =r(mean)

scalar diff_outcome= outcome1-outcome0
display diff_outcome

twoway scatter mean_unempdur age_bins || line output0 age if age<50 || line output1 age if age>=50, xlabel(46(1)54) ylabel(5(10)40) xline(50)

*Outcome equation:
reg lwage educ, robust


*Prueba de correlación:
predict r
gen diferror = lwage - r
corr diferror enroll

*choosing the best instrument:
corr educ nearc2
corr educ nearc4


*IV estimator
corr lwage nearc4, cov
global cov_yz=r(cov_12)

corr educ nearc4, cov
global cov_tz=r(cov_12)

display $cov_yz/$cov_tz

*we can also apply the 2SLS procedure and get the same result
reg educ nearc4
predict fv
reg lwage fv

*Since in this very simple model we have only one single (endogenous) regressor in the outcome equation and the instrument is a dummy variable, we can 
*get the same result using the WALD estimator:
sum lwage if nearc4==1
global y1=r(mean)
sum lwage if nearc4==0
global y0=r(mean)

sum educ if nearc4==1
global t1=r(mean)
sum educ if nearc4==0
global t0=r(mean)

display ($y1-$y0)/($t1-$t0)

*IV estimate in STATA
ivregress 2sls lwage (educ=nearc4)

Comments