lsun20 / EventStudyInteract

MIT License
35 stars 12 forks source link

Comparing estimated coefficients from different models using eventstudyinteract #9

Open RubyDoeleman opened 10 months ago

RubyDoeleman commented 10 months ago

Dear Liyang,

Thank you for your great Stata package eventstudyinteract! I am using the command to separately estimate ATTs for two subsamples in my panel data.

I want to compare the estimated coefficients for the two different subsamples to see whether they differ significantly. The Stata help file provides a way to do this by interacting the treatment dummy with the different subgroups and estimate one regression.

However, I want to separately estimate the two regressions. The Statahelp file mentions that "Alternatively, we can use eventstudyinteract separately on the two subsamples [...]", but does not provide example code to achieve this.

I have tried separately storing the result in matrices, but I cannot recall them simultaneously and use the lincom command to compare them. See stylized code below:

// generating interaction variables for sub-groups

forvalues k = 9(-1)2 {
gen ggroupzero_`k' = time_to_treat == -`k' & groupvariable == 0
}
forvalues k = 0/5 {
gen ggroupzero`k' = time_to_treat == `k' & groupvariable == 0
}

forvalues k = 9(-1)2 {
gen ggroupone_`k' = time_to_treat == -`k' & groupvariable == 1
}
forvalues k = 0/5 {
gen ggroupone`k' = time_to_treat == `k' & groupvariable == 1
}
replace ggroupzero0 = 0 if missing(first_treatment_year)
replace ggroupone0 = 0 if missing(first_treatment_year)

// first subsample

eventstudyinteract Y ggroupzero_* ggroupzero0-ggroupzero5 if groupvariable == 0, cohort(first_treatment_year) control_cohort(never_treated) absorb(i.id i.year) vce(cluster clustervariable)
matrix bgroupzero = e(b_iw)
matrix Vgroupzero = e(V_iw)
ereturn post bgroupzero Vgroupzero

// second subsample

eventstudyinteract Y ggroupone_* ggroupone0-ggroupone5 if groupvariable == 1, cohort(first_treatment_year) control_cohort(never_treated) absorb(i.id i.year) vce(cluster clustervariable)
matrix bgroupzero = e(b_iw)
matrix Vgroupzero = e(V_iw)
ereturn post bgroupone Vgroupone

// lincom to test difference lincom (ggroupzero0 + ggroupzero1 + ggroupzero2 + ggroupzero3 + ggroupzero4 + ggroupzero5)/6 - (ggroupone0 + ggroupone1 + ggroupone2 + ggroupone3 + ggroupone4 + ggroupone5)/6

If I run this, Stata tells me "ggroupzero0 not found".

Is there a way to store the estimates from eventstudyinteract and compare the ATTs from separate regressions?

Thanks a lot in advance!

Best regards, Ruby

lsun20 commented 7 months ago

Sorry for the delay @RubyDoeleman as I just saw this! Thank you for typing up the example so clearly! If you would like to run separate regressions, I think you can "trick" Stata's `lincom' by concatenating the matrices yourself.

eventstudyinteract Y ggroupzero_* ggroupzero0-ggroupzero5 if groupvariable == 0, cohort(first_treatment_year) control_cohort(never_treated) absorb(i.id i.year) vce(cluster clustervariable)
matrix bgroupzero = e(b_iw)
matrix Vgroupzero = e(V_iw)
eventstudyinteract Y ggroupone_* ggroupone0-ggroupone5 if groupvariable == 1, cohort(first_treatment_year) control_cohort(never_treated) absorb(i.id i.year) vce(cluster clustervariable)
matrix bgroupzero = e(b_iw)
matrix Vgroupzero = e(V_iw)

// use mata to concatenate the variance covariance matrices

matrix b = bgroupzero, bgroupone
mata
Vzero=st_matrix("Vgroupzero")'
Vone=st_matrix("Vgroupone")'
V = blockdiag(Vzero, Vone)
st_matrix("V",V)
end
mat coln V = `: coln Vgroupzero ' `: coln Vgroupone'
mat li V
mat rown V = `: rown Vgroupzero ' `: rown Vgroupone'

// lincom to test difference (which relies on estimates stored in b and V

ereturn post b V
lincom (ggroupzero0 + ggroupzero1 + ggroupzero2 + ggroupzero3 + ggroupzero4 + ggroupzero5)/6 - (ggroupone0 + ggroupone1 + ggroupone2 + ggroupone3 + ggroupone4 + ggroupone5)/6

I tested the above and hopefully this solves your issue. Let me know if you have any questioins.

RubyDoeleman commented 6 months ago

Thanks so much for getting back to me, Liyang! This solved the issue. :-)