Robust Inference
Driscoll-Kraay and Conley spatial HAC covariance estimators.
SpatialEconometrics.SpatialHAC.AbstractRobustVCOV — Type
AbstractRobustVCOVA robust covariance specification, passed to robust_vcov, robust_coeftable or spatial_effects.
Subtypes: DriscollKraayVCOV and ConleySpatialHAC.
SpatialEconometrics.SpatialHAC.BartlettKernel — Type
BartlettKernel()Triangular kernel, max(0, 1 - |x|). The Newey-West default and the default throughout this package: weights decline linearly to zero at the bandwidth, which guarantees a positive semi-definite covariance.
See also KernelType.
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 2matrix of positions, positional. WithHaversineDistancethe columns are latitude then longitude in degrees.dist_cutoff: distance beyond which units are treated as independent, positional, in the units ofmetric(kilometres for Haversine).
Keywords
max_time_lag: periods of serial correlation to allow;0for a cross-section.metric: aDistanceMetric.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.
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).
SpatialEconometrics.SpatialHAC.DistanceMetric — Type
DistanceMetricHow distance between two units is measured when building spatial HAC weights. Subtypes: EuclideanDistance, HaversineDistance.
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.nothingpicks a rule-of-thumb bandwidth from the number of periods.kernel: aKernelType.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).
SpatialEconometrics.SpatialHAC.EuclideanDistance — Type
EuclideanDistance()Straight-line distance in the units of the coordinates, hypot(dx, dy).
The default. Appropriate for projected coordinates; for raw latitude and longitude use HaversineDistance instead, since a degree of longitude is not a fixed distance.
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.
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())SpatialEconometrics.SpatialHAC.KernelType — Type
KernelTypeKernel used to down-weight distant observations in a HAC covariance.
Subtypes: BartlettKernel, ParzenKernel, QuadraticSpectralKernel, UniformKernel. The choice affects the weight profile but rarely the conclusion; what matters more is the bandwidth (max_lag or dist_cutoff).
SpatialEconometrics.SpatialHAC.ParzenKernel — Type
ParzenKernel()Parzen kernel: smoother decay than BartlettKernel, also guaranteeing positive semi-definiteness. Slightly more efficient when the true autocorrelation decays smoothly.
See also KernelType.
SpatialEconometrics.SpatialHAC.QuadraticSpectralKernel — Type
QuadraticSpectralKernel()Quadratic spectral kernel. Asymptotically optimal in the rate sense (Andrews, 1991) and has no hard truncation point: weights decay smoothly without ever reaching exactly zero, so every lag contributes something.
See also KernelType.
SpatialEconometrics.SpatialHAC.RobustInferenceTable — Type
RobustInferenceTableCoefficient 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.
SpatialEconometrics.SpatialHAC.UniformKernel — Type
UniformKernel()Equal weight on every lag inside the bandwidth and zero outside — the truncated, unweighted estimator.
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.
SpatialEconometrics.SpatialHAC.vcov_conley — Function
vcov_conley(Z, residuals, N, T_per, spec; bread_inv = nothing)Conley spatial HAC covariance from a score matrix directly.
The low-level routine behind robust_vcov; see vcov_driscoll_kraay for why the fitted-model path is usually the one you want. spec is a ConleySpatialHAC, which carries the coordinates, cutoff, metric and kernels.
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 Kregressor 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.nothinguses the OLS form.spec: aDriscollKraayVCOVcarrying the kernel and bandwidth.