JMSLab / xtevent

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

Check vce vs. cluster for IV estimation without reghdfe. #104

Closed jorpppp closed 1 year ago

Constantino-Carreto-Romero commented 2 years ago

This issue is related to issue #12. There, I only solved for the case when the user indicates IV estimation and the option reghdfe. In that setting, xtevent uses the estimation command ivreghdfe, which does not allow the use of vce.

In the IV setting without the option reghdfe, xtevent uses the estimation commands xtivreg (the default) or ivregress (if the user specifies the option nofe). The bug in #104 arises because xtivreg only allows vce for specifying the way to compute the standar errors. Other ways to specify it (e.g. cluster, robust) are not allowed.

To solve it, I will add some code, so for instance, if the user specifies cluster(id) we can translate it to vce(cluster id).

I looked for standard-error specification limitations in the other estimation commands used in xtevent (in both ols and IV), but I didn't find any problem.

Constantino-Carreto-Romero commented 1 year ago

@jorpppp in https://github.com/JMSLab/xtevent/commit/c4dccbd9606977161d197d5af27877ae14ef309e I added some code so now the options cluster() and robust can be specified in the IV setting when option reghdfe is not specified.

These are some examples to check it:

*install the branch version 
net install xtevent, from("https://raw.githubusercontent.com/JMSLab/xtevent/issue104_options_cluster_robust_not_allowed") replace

*load example31 dataset
use "https://github.com/JMSLab/xtevent/blob/main/test/example31.dta?raw=true", clear

*default IV
xtevent y, pol(z) panelvar(i) timevar(t) window(3) proxy(x)

**** cluster() and robust are passed to vce()
*cluster 
xtevent y, pol(z) panelvar(i) timevar(t) window(3) proxy(x) cluster(i)
xtevent y, pol(z) panelvar(i) timevar(t) window(3) proxy(x) cl(i)

*robust 
xtevent y, pol(z) panelvar(i) timevar(t) window(3) proxy(x) robust //although, it also clusters 
xtevent y, pol(z) panelvar(i) timevar(t) window(3) proxy(x) r

*if cluster + robust, only pass cluster to vce
xtevent y, pol(z) panelvar(i) timevar(t) window(3) proxy(x) cluster(i) r

*if the user already specified vce, then execute as originally specified. expect an error:
xtevent y, pol(z) panelvar(i) timevar(t) window(3) proxy(x) vce(robust) cluster(i) //option cluster() not allowed
xtevent y, pol(z) panelvar(i) timevar(t) window(3) proxy(x) vce(cluster i) r //options vce() and robust may not be combined
xtevent y, pol(z) panelvar(i) timevar(t) window(3) proxy(x) vce(bootstrap) cluster(i) //option cluster() not allowed

*specify additional options
xtevent y, pol(z) panelvar(i) timevar(t) window(3) proxy(x) cluster(i) level(90) first