JMSLab / xtevent

Stata package -xtevent-
MIT License
44 stars 12 forks source link

Difference of averages doesn't include all coefficients #189

Closed Constantino-Carreto-Romero closed 6 months ago

Constantino-Carreto-Romero commented 7 months ago

Per comment https://github.com/JMSLab/xtevent/pull/178#issuecomment-2093897496

When executing

use example31, clear
xtevent y eta, panelvar(i) timevar(t) pol(z) impute(stag) window(max) diffavg 

There is a bug because we get a calculated left endpoint of -19, but the computation of the difference of averages only includes until coefficient -9.

Constantino-Carreto-Romero commented 6 months ago

@jorpppp The section code of diffavg is currently placed on this line in _eventols https://github.com/JMSLab/xtevent/blob/77b42a83a3f692fef9a82a8b0e5bdb928b714c7e/xtevent/_eventols.ado#L583 just before the code to adjust for a trend by GMM. Therefore, diffavg doesn't reflect the adjustment, if any. I'm moving the diffavg code to this line: https://github.com/JMSLab/xtevent/blob/77b42a83a3f692fef9a82a8b0e5bdb928b714c7e/xtevent/_eventols.ado#L681 after the trend adjustment code.

Constantino-Carreto-Romero commented 6 months ago

@jorpppp in https://github.com/JMSLab/xtevent/commit/42d88ea4f42cd729752940da04a409f777cd3d91 I changed how diffavg selects the pre and post coefficients, so it doesn't rely on string matching. Instead, it relies on the local that indicates the omitted coefficients. For instance, when running:

xtevent y eta, panelvar(i) timevar(t) pol(z) impute(stag) window(max) trend(-2, method(ols))  diffavg 

I get the following output, which includes all event-time coefficients except for coefficients -2 and -1.

jorpppp commented 6 months ago

Thanks @Constantino-Carreto-Romero , looks good. Can you start a PR for this please?

Constantino-Carreto-Romero commented 6 months ago

Summary: in this issue we fixed a bug in diffavg which was missing event-time coefficients in the computation of the difference of averages. Thread continues in https://github.com/JMSLab/xtevent/pull/190