Robust Inference

Driscoll-Kraay and Conley spatial HAC covariance estimators.

SpatialEconometrics.SpatialHAC.ConleySpatialHAC — Type
ConleySpatialHAC(coords, dist_cutoff; max_time_lag = 0, metric = EuclideanDistance(),
                 space_kernel = BartlettKernel(), time_kernel = BartlettKernel(),
                 psd_fix = true)

Conley spatial HAC covariance: correlation decaying with geographic distance.

Pairs of units closer than dist_cutoff contribute to the covariance with a kernel weight based on their distance; pairs beyond it contribute nothing. Unlike DriscollKraayVCOV this needs coordinates, but in exchange it works with few time periods and with pure cross-sections.

Arguments

  • coords: N x 2 matrix of positions, positional. With HaversineDistance the columns are latitude then longitude in degrees.
  • dist_cutoff: distance beyond which units are treated as independent, positional, in the units of metric (kilometres for Haversine).

Keywords

  • max_time_lag: periods of serial correlation to allow; 0 for a cross-section.
  • metric: a DistanceMetric.
  • space_kernel, time_kernel: KernelTypes for the spatial and temporal dimensions.
  • psd_fix: project the result to the nearest positive semi-definite matrix if the kernel weighting leaves it indefinite. Keep this on unless you are diagnosing the covariance itself.
Note

dist_cutoff is a judgement call and the result is sensitive to it: too small and spatial correlation is missed, too large and the estimate is noisy. Report standard errors at a couple of cutoffs.

Examples

m = fit_spatial(SAR(), W, X, y)
robust_coeftable(m, ConleySpatialHAC(coords, 3.0))

ConleySpatialHAC(coords, 150.0; metric = HaversineDistance(), max_time_lag = 2)

References

Conley, T. (1999). GMM estimation with cross sectional dependence. Journal of Econometrics, 92(1).

source
SpatialEconometrics.SpatialHAC.DriscollKraayVCOV — Type
DriscollKraayVCOV(; max_lag = nothing, kernel = BartlettKernel(), small_sample_correct = true)

Driscoll-Kraay spatially-correlated-consistent covariance for panel data.

Averages the scores across units within each period and then applies a Newey-West correction over periods. Because the cross-sectional dependence is handled by that averaging, it is robust to arbitrary spatial correlation — no distance, coordinates or cutoff are needed — as well as to heteroskedasticity and serial correlation.

The price is that it leans on having a reasonable number of time periods; with very short panels the time-series correction is poorly estimated, and ConleySpatialHAC is the better choice when you have coordinates and few periods.

Keywords

  • max_lag: lag truncation. nothing picks a rule-of-thumb bandwidth from the number of periods.
  • kernel: a KernelType.
  • small_sample_correct: apply the finite-sample degrees-of-freedom scaling.

Examples

m = fit_spatial_panel(SAR(), W, X, y, N, T; fe = TwoWayFE())
robust_coeftable(m, DriscollKraayVCOV())
robust_coeftable(m, DriscollKraayVCOV(max_lag = 5, kernel = ParzenKernel()))

References

Driscoll, J. & Kraay, A. (1998). Review of Economics and Statistics, 80(4).

source
SpatialEconometrics.SpatialHAC.HaversineDistance — Type
HaversineDistance(; radius_km = 6371.0088)

Great-circle distance in kilometres between points given as (latitude, longitude) in degrees.

Use this whenever coordinates are unprojected geographic degrees. The default radius is the Earth's mean radius.

Note

Column order is latitude first, then longitude, and the cutoff you pair it with is therefore in kilometres.

Examples

spec = ConleySpatialHAC(coords, 150.0; metric = HaversineDistance())
source
SpatialEconometrics.SpatialHAC.RobustInferenceTable — Type
RobustInferenceTable

Coefficient table pairing robust with model-based standard errors, returned by robust_coeftable. Pretty-prints via show.

Fields

  • estimator_name: which robust estimator was used.
  • coefnames, coef: parameter names and estimates.
  • se_robust, se_baseline: robust and model-based standard errors. The ratio between them is the diagnostic worth reading.
  • z_robust: coef ./ se_robust.
  • vcov_robust: the full robust covariance.
source
SpatialEconometrics.SpatialHAC.UniformKernel — Type
UniformKernel()

Equal weight on every lag inside the bandwidth and zero outside — the truncated, unweighted estimator.

Warning

Unlike the other kernels this does not guarantee a positive semi-definite covariance matrix, so standard errors can come out undefined. Use it only when you have a reason to.

See also KernelType.

source
SpatialEconometrics.SpatialHAC.vcov_driscoll_kraay — Function
vcov_driscoll_kraay(Z, residuals, N, T_per; bread_inv = nothing, spec = DriscollKraayVCOV())

Driscoll-Kraay covariance from a score matrix directly.

The low-level routine behind robust_vcov. Prefer that on a fitted model, which builds Z and bread_inv correctly for you — in particular it maps maximum-likelihood scores through the Jacobian of the spatial transformation, which a raw call here will not do.

Arguments

  • Z: (N*T_per) x K regressor or score matrix, stacked with units varying fastest within each period.
  • residuals: matching residual vector.
  • N, T_per: units and periods.

Keywords

  • bread_inv: the (X'X)^{-1}-analogue for the sandwich. nothing uses the OLS form.
  • spec: a DriscollKraayVCOV carrying the kernel and bandwidth.
source