conley
Compute spatial and spatio-temporal HAC standard errors for OLS regressions using a distance-cutoff kernel, yielding valid inference when observations are geographically correlated.
Instructions
Compute Conley (1999) spatial -- and optionally spatio-temporal -- HAC Validation: validated evidence tier (known-truth, reference, external-parity, or Monte Carlo artifact). Cost: Sparse and scale-safe: a scipy cKDTree ball query enumerates only observation pairs within dist_cutoff, so memory is O(n + pairs-within-cutoff) rather than O(n^2). This is the recommended Conley path on large samples -- unlike feols(vce='conley') / hdfe_ols(vce='conley'), which are dense. Cost still grows with dist_cutoff: a cutoff large enough to link most observations recovers the quadratic pair count.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lat | Yes | Column name for latitude. | |
| lon | Yes | Column name for longitude. | |
| time | No | Column name holding the time period. Must be integer-valued. Requires ``lag_cutoff`` and ``unit``. | |
| unit | No | Column name identifying the panel unit. Enables panel de-duplication: the spatial neighbour search runs on the distinct unit coordinates rather than on every row, so a unit observed T times costs one point in the KD-tree instead of T. | |
| alpha | No | Significance level for confidence intervals. | |
| detail | No | Payload depth: 'minimal' (~150 tokens) for sub-step calls where only the point estimate is needed; 'standard' (~1K tokens) for diagnostics + coefficient table; 'agent' (~2K tokens, default) adds violations / next_steps / suggested_functions so the LLM can plan its next call without another round-trip. | agent |
| kernel | No | Spatial kernel: ``"uniform"`` (indicator) or ``"bartlett"`` (linearly declining weight ``1 - d/h``). | uniform |
| result | Yes | Fitted OLS result. Must have ``data_info`` containing ``'X'`` (design matrix), ``'y'`` (response), and ``'residuals'``. | |
| distance | No | ``"haversine"`` uses great-circle distance on a sphere of radius 6371 km, and is symmetric. ``"planar"`` reproduces ``acreg``'s convention exactly: 111 km per degree of latitude and ``cos(lat_ref) * 111`` km per degree of longitude, anchored at the *reference* point, which makes the distance asymmetric; the resulting covariance is symmetrised the same way ``acreg`` does (Mata ``_makesymmetric``, which mirrors the lower triangle). Choose ``"planar"`` for bit-level ``acreg`` parity, ``"haversine"`` for a proper great-circle metric. | haversine |
| as_handle | No | If true, cache the fitted result on the server and return result_id + result_uri alongside the JSON payload so a subsequent tools/call can chain without re-running. | |
| data_path | Yes | Absolute path or URL to a data file. Supported: .csv / .tsv / .txt (delimited), .parquet / .pq, .feather / .arrow, .xlsx / .xls, .dta (Stata), .json / .jsonl. Schemes: file://, s3://, gs://, https://. | |
| result_id | No | Optional handle to a previously-fitted result (returned by an earlier call when as_handle=true). Tools that operate on a fitted object accept this in place of re-supplying data_path + columns. | |
| lag_cutoff | No | Serial-correlation bandwidth in periods, for pairs within the same unit. Requires ``time``. | |
| dist_cutoff | Yes | Distance cutoff *h* in kilometres. Pairs farther apart than this receive zero weight. | |
| time_kernel | No | Time kernel: ``"bartlett"`` (``1 - |dt| / (lag_cutoff + 1)``, the Newey-West convention, matching ``acreg``'s ``hac bartlett``) or ``"uniform"`` (indicator, matching ``acreg`` without ``hac``). | bartlett |
| data_columns | No | Optional column projection. Parquet/Feather/Stata loaders honour this for fast partial reads. | |
| data_sample_n | No | Optional uniform random subsample size (seed=0, deterministic) — useful on huge panels. | |
| lag_cutoff_cross | No | Time bandwidth for pairs drawn from *different* units -- ``acreg``'s ``lagdist()``. Defaults to ``0`` (``acreg``'s default), i.e. contemporaneous cross-unit correlation only. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||