Home  /  Products  /  Stata 19  /  More VCE options for linear models

← See Stata 19's new features

Highlights

  • Heteroskedasticity- and autocorrelation-consistent standard errors in linear regression models

  • Driscoll–Kraay standard errors in panel fixed-effects regression

  • Enhanced bias correction in linear regression models

    • HC3 with clustering in regress

    • HC3 standard errors, including with clustering, in areg and xtreg, fe

    • HC2 and HC3 with clustering in didregress and xtdidregress

    • Hansen (2025) corrected inference with HC3 standard errors

  • Multiway cluster–robust standard errors in linear instrumental-variables regression

  • Unstructured covariance matrix among time periods in panel generalized least squares

  • See more linear models features

Stata's most commonly used linear regression commands now come with a richer set of variance–covariance matrix (VCE) options, allowing standard errors and confidence intervals that are robust in even more situations. These features are part of StataNow™.

Are errors in your model for time-series or panel data autocorrelated? regress and areg now allow for heteroskedasticity- and autocorrelation-consistent (HAC) standard errors with the vce(hac) option, while xtreg, fe allows users to specify Driscoll–Kraay standard errors with the new vce(dkraay) option.

Bias correction has been enhanced in regress, areg, xtreg, fe, didregress, and xtdidregress, with each now allowing for both HC2 and HC3 standard errors with clustering. The inference adjustment of Hansen (2025) is also available with HC3 standard errors using the new hansen suboption.

Now you can also account for multiple nonnested clusters when fitting an instrumental-variables (IV) regression with ivregress. And when you fit linear models via generalized least squares with xtgls, you can now allow for arbitrary correlation within panels with the new corr(unstructured) option.

Let's see it work

We can use Driscoll–Kraay standard errors to evaluate the effect of union membership (union) on the log of wages (ln_wage). We control for job tenure and for time fixed effects.

Driscoll–Kraay standard errors are often useful in panel settings where errors may be correlated over time. These standard errors are robust not only to heteroskedasticity and autocorrelation but also to general forms of dependence between panels (see Driscoll and Kraay [1998] for details).

Here we type

. webuse nlswork
(National Longitudinal Survey of Young Women, 14-24 years old in 1968)

. xtreg ln_wage tenure union, fe vce(dkraay nwest opt)

Fixed-effects (within) regression               Number of obs     =     19,010
Group variable: idcode                          Number of groups  =      4,134

R-squared:                                      Obs per group:
     Within  = 0.1030                                         min =          1
     Between = 0.1923                                         avg =        4.6
     Overall = 0.1407                                         max =         12

                                                F(2, 11)          =     161.79
corr(u_i, Xb) = 0.1426                          Prob > F          =     0.0000

DK robust
ln_wage Coefficient std. err. t P>|t| [95% conf. interval]
tenure .0262867 .0020694 12.70 0.000 .021732 .0308413
union .098657 .013426 7.35 0.000 .0691065 .1282074
_cons 1.629107 .0220478 73.89 0.000 1.58058 1.677634
sigma_u .4004797
sigma_e .2598383
rho .70374743 (fraction of variance due to u_i)
Driscoll–Kraay VCE: Bartlett kernel with 11 lags Driscoll–Kraay lags: Chosen by Newey–West method

We have requested Driscoll–Kraay standard errors with the Bartlett kernel and that lags be chosen using the Newey–West criterion for optimal lags. We could have alternately requested a Parzen or quadratic spectral kernel. The vce() option syntax for Driscoll–Kraay standard errors is the same as the syntax for HAC standard errors in ivregress and now in regress and areg but with dkraay substituted for hac.

Here the confidence interval for union is wider than if we had used the vce(robust) option to estimate cluster–robust standard errors.

Because Driscoll–Kraay standard errors account for heteroskedasticity and correlation, they tend to perform better than ordinary standard errors even in relatively short panels as in these data (Driscoll and Kraay 1998). However, note that Driscoll–Kraay standard errors, like HAC standard errors, rely on asymptotic properties that take effect as the number of time periods becomes large.

We may prefer to estimate standard errors that are robust to correlation within clusters defined by birth year (birth_yr). Because we have only 14 clusters and their sizes are unbalanced (3 birth years have far fewer observations than the other 11), we apply an HC3 bias correction with the adjustments of Hansen (2025). We type

. xtreg ln_wage tenure union, fe vce(hc3 birth_yr, dfadjust hansen)

Computing degrees of freedom ...

Fixed-effects (within) regression               Number of obs     =     19,010
Group variable: idcode                          Number of groups  =      4,134

R-squared:                                      Obs per group:
     Within  = 0.1030                                         min =          1
     Between = 0.1923                                         avg =        4.6
     Overall = 0.1407                                         max =         12

                                                F(2, 13)          =     403.60
corr(u_i, Xb) = 0.1426                          Prob > F          =     0.0000

                              (Std. err. adjusted for 14 clusters in birth_yr)
Robust HC3
ln_wage Coefficient std. err. t P>|t| [95% conf. interval]
tenure .0262867 .0019327 13.60 0.000 .0221852 .0303882
union .098657 .0095187 10.36 0.000 .078401 .1189129
_cons 1.629107 .0064638 252.04 0.000 1.615392 1.642822
sigma_u .4004797
sigma_e .2598383
rho .70374743 (fraction of variance due to u_i)
Note: p-values computed using adjusted degrees of freedom and Hansen scaling.

The confidence interval for union is wider than the standard cluster–robust confidence interval we would have obtained with vce(cluster birth_yr).

Using vce(hc3) with the hansen suboption yields the same small-sample degrees-of-freedom adjustment as with using only the dfadjust suboption, but it also applies a scaling factor to the t distribution used to generate the confidence interval.

Here we have demonstrated the new Hansen adjustment with the xtreg, fe command, but the same adjustment is also now available with regress, areg, didregress, and xtdidregress.

Also, make sure to explore multiway clustering in ivregress and the new corr(unstructured) option in xtgls, which allows for unstructured correlation across time periods within panels.

References

Driscoll, J. C., and A. C. Kraay. 1998. Consistent covariance matrix estimation with spatially dependent panel data. The Review of Economics and Statistics 80: 549–560.

Hansen, B. E. 2025. Standard errors for difference-in-difference regression. Journal of Applied Econometrics 40: 291–309.

Ready to get started?

Experience powerful statistical tools, reproducible workflows, and a seamless user experience—all in one trusted platform.