Written and maintained by CASRAI Editorial Board
Published
On this page
Newey-West standard errors are heteroskedasticity- and autocorrelation-consistent (HAC) standard errors: they correct the standard errors, t-statistics and confidence intervals of a regression when the residuals have unequal variance and are correlated across time, without changing the coefficient estimates. The estimator adds weighted lagged cross-products of the residuals to the usual robust “sandwich” covariance matrix, so the weights shrink as the lag grows and the result stays positive semi-definite.
Definition: what Newey-West (HAC) standard errors are
Ordinary least squares (OLS) standard errors assume the errors are uncorrelated with constant variance. With time-series data, residuals often move together from one period to the next, so those assumptions fail and the classical standard errors can be misleading. The Newey-West estimator, introduced by Newey and West (1987) in Econometrica 55, 703-708 (“A Simple, Positive Semi-Definite, Heteroskedasticity and Autocorrelation Consistent Covariance Matrix”), keeps the OLS coefficients and replaces only the covariance matrix used for inference. Software documentation uses the labels “HAC” and “Newey-West” interchangeably, which is why you will see both in the same output option list.
It extends the heteroskedasticity-only corrections described in robust standard errors (HC0 to HC3): with the number of lags set to zero, the Newey-West estimator reduces to White’s HC0 estimator. The statsmodels documentation for its HAC covariance function states this directly, noting that the implementation is verified only for nlags=0, “which is just White”.
Formula with every symbol explained
For a regression y = Xβ + ε with n observations and k coefficients, the Newey-West covariance matrix of the OLS estimator is a sandwich:
V = (X’X)-1 S (X’X)-1, where S = Γ0 + Σl=1..L wl (Γl + Γl‘), Γl = Σt=l+1..n et et-l xt xt-l‘, and wl = 1 – l/(L+1).
- X is the n × k matrix of regressors and xt is its row (as a column vector) for period t.
- et is the OLS residual in period t.
- Γ0 is the sum of et2 xt xt‘. On its own, (X’X)-1 Γ0 (X’X)-1 is the White HC0 estimator.
- Γl is the lag-l cross-product of the “scores” xt et; adding its transpose Γl‘ keeps S symmetric.
- L is the maximum lag (also called the bandwidth or truncation lag).
- wl is the Bartlett kernel weight, which falls linearly from near 1 at lag 1 to 1/(L+1) at lag L. The weights are what guarantee S is positive semi-definite.
The standard error of coefficient j is the square root of the j-th diagonal element of V. Software may multiply V by a small-sample factor n/(n-k); the next sections show where that is on or off by default.
Newey-West lag selection: how to choose L
The one tuning decision is the lag length. Three documented conventions matter in practice, and the data table below compares them side by side.
- statsmodels, cov_hac: if nlags is not given, the default is floor[4(T/100)2/9], where T is the number of observations. For T = 12 this is 2. The function uses the Bartlett kernel and applies a small-sample correction by default (use_correction=True).
- statsmodels, results.get_robustcov_results: with cov_type=’HAC’ you must supply maxlags yourself, and you can choose kernel ‘bartlett’ (the default) or ‘uniform’.
- R, sandwich::NeweyWest: if lag is NULL, the lag is floor(bwNeweyWest(x)), the automatic bandwidth of Newey and West (1994, Review of Economic Studies 61, 631-653, “Automatic Lag Selection in Covariance Matrix Estimation”). By default it also applies VAR(1) prewhitening (prewhite=TRUE) and leaves the n/(n-k) factor off (adjust=FALSE).
The practical consequence is that the same regression can give different “Newey-West” standard errors in R and Python even though both are correct: the defaults differ in lag rule, prewhitening and small-sample scaling. To reproduce the 1987 estimator exactly in R, the package documentation says to specify the lag and set prewhite=FALSE. Always report the lag, the kernel and whether prewhitening or a small-sample correction was applied.
Worked example with real numbers and the arithmetic shown
This is an illustrative composite dataset made up for teaching, not data from a study. Take n = 12 periods, x = 1, 2, …, 12 and y = 3.3, 4.3, 5.0, 5.4, 5.7, 6.2, 7.1, 8.3, 9.6, 10.6, 11.3, 11.7, and fit y = a + b·x by OLS with L = 2.
Step 1, OLS fit. The mean of x is 6.5, the mean of y is 7.375 and Sxx = Σ(x – 6.5)2 = 143. The slope is b = 0.7843 and the intercept is a = 2.2773. The residuals et are 0.238, 0.454, 0.370, -0.014, -0.499, -0.783, -0.667, -0.251, 0.264, 0.480, 0.396, 0.012. They drift slowly up and down rather than alternating, and the lag-1 residual autocorrelation (Σetet-1 / Σet2) is 0.72, the situation HAC errors are designed for (see the guide on testing for autocorrelated residuals).
Step 2, slope-score products. For the slope in a simple regression the sandwich reduces to a scalar. Let ut = (xt – 6.5)·et. The u values are -1.3115, -2.0439, -1.2948, 0.0358, 0.7479, 0.3914, -0.3336, -0.3771, 0.6608, 1.6802, 1.7811, 0.0635.
Step 3, autocovariances. γ0 = Σut2 = 14.9776; γ1 = Σutut-1 = 9.5622; γ2 = Σutut-2 = 0.7031.
Step 4, Bartlett weights for L = 2. w1 = 1 – 1/3 = 0.6667 and w2 = 1 – 2/3 = 0.3333.
Step 5, combine. S = γ0 + 2·w1·γ1 + 2·w2·γ2 = 14.9776 + 2(0.6667)(9.5622) + 2(0.3333)(0.7031) = 14.9776 + 12.7496 + 0.4687 = 28.1960. The variance of the slope is S / Sxx2 = 28.1960 / 1432 = 0.0013788, so the Newey-West standard error is √0.0013788 = 0.0371.
Verified with code: the statsmodels call with maxlags=2 and use_correction=False returns the same slope standard error, 0.0371. With use_correction=True it returns 0.0407, which equals 0.0371 × √(12/10).
Interpretation: what the result means
The slope of 0.7843 is identical under every method. Only its uncertainty changes. For this dataset the standard errors for the slope are:
| Method | Slope SE | t for b = 0.7843 |
|---|---|---|
| Classical OLS | 0.0395 | 19.87 |
| White HC0 (L = 0) | 0.0271 | 28.98 |
| Newey-West, L = 2, no correction | 0.0371 | 21.12 |
| Newey-West, L = 2, n/(n-k) correction | 0.0407 | 19.28 |
Reading guidance: compare Newey-West with the HC0 value to see what the autocorrelation terms add (here they raise the standard error from 0.0271 to 0.0371, because the positive γ1 and γ2 are added). Do not assume a Newey-West standard error is always larger than the classical one; in this example it is slightly smaller than the classical OLS value, because the HAC estimate also reflects the pattern of the regressor and residuals, not only the amount of autocorrelation. Using the t distribution with n – k = 10 degrees of freedom (critical value 2.228), the 95% interval for the slope is 0.7843 ± 2.228 × 0.0371, that is [0.702, 0.867].
Assumptions and common mistakes
- It is a large-sample method. The consistency argument needs many time periods; n = 12 is used above only so the arithmetic fits on a page.
- The lag must grow slowly with the sample. Too small an L leaves autocorrelation uncorrected; too large an L adds noise. Do not simply try several values and keep the most significant one.
- It corrects inference, not the model. If autocorrelation comes from a missing lag or trend, adding it to the model is a different fix. See autocorrelation in time-series data and, for a design that relies on segmented regression, interrupted time series analysis.
- It is not for cross-sectional dependence. In panel data where units are correlated with each other in the same period, Newey-West on its own does not address that; panel-specific estimators such as Driscoll-Kraay are used instead.
- Comparing across software without matching settings. Differences in lag rule, prewhitening and the small-sample factor, shown in the data table, explain most “my R and Stata output disagree” cases.
- Reporting only “robust standard errors”. Name the estimator, kernel and lag.
How to report Newey-West standard errors (APA example)
Name the estimator, the kernel, the lag and how the lag was chosen, then report the coefficient with its interval. An illustrative sentence for the example above: “Time was positively associated with the outcome, b = 0.78, 95% CI [0.70, 0.87], t(10) = 21.12, p below .001, using Newey-West (Bartlett kernel, L = 2) heteroskedasticity- and autocorrelation-consistent standard errors (Newey and West, 1987).” The reference entry is: Newey, W. K., and West, K. D. (1987). A simple, positive semi-definite, heteroskedasticity and autocorrelation consistent covariance matrix. Econometrica, 55, 703-708. If you let software choose the lag, cite Newey and West (1994) as well and say so.
How to calculate Newey-West standard errors in Excel, R or Python
Python (statsmodels)
Fit the OLS model, then request HAC errors with an explicit lag:
import statsmodels.api as sm; X = sm.add_constant(x); res = sm.OLS(y, X).fit(cov_type='HAC', cov_kwds={'maxlags': 2, 'use_correction': False}); print(res.bse)
For the example data this prints the slope standard error 0.0371. Setting use_correction to True applies the small-sample factor.
R (sandwich and lmtest)
fit = lm(y ~ x); library(sandwich); library(lmtest); coeftest(fit, vcov = NeweyWest(fit, lag = 2, prewhite = FALSE, adjust = FALSE))
Specifying lag and prewhite = FALSE reproduces the 1987 estimator; calling NeweyWest(fit) with defaults uses the 1994 automatic lag and VAR(1) prewhitening, so its numbers will differ.
Excel
Excel has no built-in HAC option, but the simple-regression slope can be built by hand. Put x in A2:A13, y in B2:B13, centred x in C2:C13 (=A2-AVERAGE($A$2:$A$13)), residuals in D2:D13 (=B2-INTERCEPT($B$2:$B$13,$A$2:$A$13)-SLOPE($B$2:$B$13,$A$2:$A$13)*A2) and products in E2:E13 (=C2*D2). Then compute γ0 = SUMPRODUCT(E2:E13,E2:E13), γ1 = SUMPRODUCT(E3:E13,E2:E12), γ2 = SUMPRODUCT(E4:E13,E2:E11), S = γ0 + 2*(2/3)*γ1 + 2*(1/3)*γ2 and SE = SQRT(S)/SUMSQ(C2:C13). For several regressors, use R or Python.
The data table below compares the documented defaults of the three software routes used here.
Sources
- statsmodels: sandwich_covariance.cov_hac, checked 2026-11-18
- statsmodels: RegressionResults.get_robustcov_results, checked 2026-11-18
- R sandwich package: NeweyWest help page (RDocumentation), checked 2026-11-18
- CRAN: Package sandwich, checked 2026-11-18
Data: Documented Newey-West (HAC) defaults in statsmodels and R sandwich
Compares how three documented software routes set the lag, kernel, prewhitening and small-sample correction for Newey-West standard errors. Compiled from the statsmodels cov_hac and get_robustcov_results documentation pages and the R sandwich NeweyWest help page, read on 2026-11-18.
| Software route | Lag rule | Kernel | Prewhitening | Small-sample correction |
|---|---|---|---|---|
| statsmodels cov_hac (defaults) | nlags=None gives floor[4(T/100)^(2/9)] | Bartlett (only kernel currently) | None | use_correction=True by default |
| statsmodels get_robustcov_results, cov_type='HAC' | maxlags is required (an integer you supply) | bartlett (default) or uniform | None | use_correction is an argument (True/False) |
| R sandwich NeweyWest (defaults) | lag=NULL gives floor(bwNeweyWest(x)), the Newey-West (1994) automatic bandwidth | Bartlett | VAR(1) prewhitening (prewhite=TRUE) | adjust=FALSE; TRUE multiplies by n/(n-k) |
| R sandwich NeweyWest, 1987 recipe | User-specified lag | Bartlett | prewhite=FALSE | adjust=FALSE unless set to TRUE |
Sources
- statsmodels: sandwich_covariance.cov_hac (accessed 2026-11-18)
- statsmodels: RegressionResults.get_robustcov_results (accessed 2026-11-18)
- R sandwich: NeweyWest help page (accessed 2026-11-18)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







