help vce2way

Title

vce2way -- A one-stop solution for robust inference with two-way clustering

Syntax

vce2way
cmdline_main
,
cluster(varname1 varname2)
[cmdline_options]

Description

Notes: As of June 2019, vce2way has been superseded by vcemway that allows for robust inference with m-way clustering, where m is 2 or larger.

vce2way is a module to adjust an existing Stata estimation command's standard errors for two-way clustering in varname1 and varname2.
The module works with any Stata command which allows one-way clustering in each dimension separately via built-in vce(cluster varname) option.
The results are compatible with the underlying command's postestimation tools that make use of ereturn matrix e(V) including test, nlcom, margins to name a few.

In the required option cluster(varname1 varname2), varname1 and varname2 are the names of variables identifying two clustering dimensions.
In the remaining syntax diagram, cmdline_main (cmdline_options) is the non-optional (optional) component of the command line to execute a command
for which two-way clustering is requested. For specific examples, see below.

Perhaps the easiest way to understand vce2way's syntax diagram is by posing the following question.
If Stata had built-in cluster(varname1 varname2) option to request two-way clustering, what command line would the researcher specify? Prefixing the answer to this question by vce2way satisfies the syntax requirements.

As Cameron et al. (2011) show, two-way clustered variance-covariance matrix V_twoway can be derived as:

V_twoway = V_1 + V_2 - V_12

where V_1, V_2 and V_12 are variance-covariance matrices adjusted for one-way clustering in varname1, varname2 and their intersection respectively.
Two-way clustered standard errors are the square roots of the diagonal elements of V_twoway.

To obtain V_1, V_2 and V_12, vce2way repeats the relevant estimation run (i.e. cmdline_main [, cmdline_options]) three times.
The resulting V_twoway is saved in e(V).
For commands which can be executed within a few seconds, this repeated estimation approach is unlikely to be an issue.
For commands which require numerical optimization of advanced non-linear models, for example asroprobit, this can be a source of major inconvenience if not practical infeasibility.
If needed, the researcher may save computer run time by using from() or init() option in conjunction with vce2way, to start the three estimation runs from
an optimal solution computed prior to executing vce2way. See the clogit example below.

Cameron et al. (2011) point out that in some applications, V_twoway may not be positive semi-definite.
As a solution, they suggest that the researcher may replace negative eigenvalues of V_twoway with 0s, and reconstruct the variance-covariance matrix
using the updated eigenvalues and the original eigenvectors. Where applicable, vce2way applies this method and displays an appropriate notice.

In terms of small sample bias corrections to the variance-covariance matrices, vce2way is like cgmreg of Gelbach and Miller (2009).
Specifically, vce2way applies the first correction method of Cameron et al. (2011, p.241) which adjusts each of the three one-way clustered matrices separately
according to the number of clusters affecting that matrix. As Baum et al. (2010) point out, their ivreg2 applies the second method of Cameron et al. (2011, p.241)
which adjusts all three matrices by a common factor based on the number of clusters in either varname1 or varname2, depending on which is smaller.
This potential variation in bias correction methods should be kept in mind when comparing the output of vce2way with that of other user-written commands
which implement two-way clustering.

Examples

In all examples below, there is only a small number of clusters in the second dimension, year.
As Baum et al. (2010) point out in the context of their ivreg2, the results should be interpreted with caution: V_twoway is consistent when
the sizes of clusters in both varname1 and varname2 become arbitrarily large.

OLS regression with two-way clustering:

. webuse nlswork, clear

. vce2way regress ln_wage age grade, cluster(idcode year)

Random-effects GLS regression with two-way clustering:

. webuse nlswork, clear

. vce2way xtreg ln_wage age grade, cluster(idcode year) re nonest

Probit with two-way clustering. By default, iteration logs are suppressed. Use noisily to display them.

. webuse union, clear

. vce2way probit union age grade, cluster(idcode year)

. vce2way noisily probit union age grade, cluster(idcode year)

Fixed-effects logit with two-way clustering and user-supplied starting values to save run time:

. webuse union, clear

. clogit union age grade not_smsa, group(idcode)

. matrix start = e(b)

. vce2way clogit union age grade not_smsa, cluster(idcode year) group(idcode) nonest from(start)

Stored results

vce2way adds the following to e():

Scalars

e(N_clust1) number of clusters in varname1

e(N_clust2) number of clusters in varname2

Macros

e(vce2way) yes

e(clustvar1) varname1

e(clustvar2) varname2

Matrices

e(V_raw) initial non-psd V_twoway in case its negative eigenvalues have been replaced to construct final e(V)

References

Baum, C.F., M.E. Schaffer, and S. Stillman. 2010. ivreg2: Stata module for extended instrumental variables/2SLS, GMM and AC/HAC, LIML and k-class regression. http://ideas.repec.org/c/boc/bocode/s425401.html.

Cameron, A. C., J.B. Gelbach, and D.L. Miller. 2011. Robust Inference With Multiway Clustering. Jorunal of Business and Economic Statistics 29(2): 238-249.

Gelbach, J.B., and D.L. Miller. 2009. Multi-way clustering with OLS. http://faculty.econ.ucdavis.edu/faculty/dlmiller/statafiles/.

Author

Dr. Hong Il Yoo

Durham University Business School

Durham University

Durham, UK

h.i.yoo@durham.ac.uk

Also see

Help: ivreg2 (if installed), vce_option