AI Agents & Econometric Coding

Time series

Granger causality

A Granger test asks whether lags of one series improve forecasts of another within a declared information set.

The task

Task statement

Test whether y2 Granger-causes y1 with two lags using the aligned OLS F-test. Report rows F, df_num, df_den, and p_value.

Data

Columns: t, y1, y2.

Files
input.csv

Required output

Scored estimates: F, df_num, df_den, p_value.

Reference output

TermReference estimateSample size
F2.8101012198
df_num2198
df_den193198
p_value0.062664313198

A run succeeds when every scored estimate lies within 1 percent or 0.005 of its reference value, whichever is larger. Sample sizes are not scored.

Task success

Agency conditionClaude Sonnet 4.6GPT-5.6 Luna
Chatbot96.7%98.3%
Self-repair98.3%100.0%
Constrained agent100.0%100.0%
All runs
98.9% of 360 runs
By prompt condition
Zero-shot 98.3%, One-shot 99.4%
By software
Python 100.0%, R 100.0%, Stata 96.7%

A prediction question

Let the equation for $y_t$ include two lags of both $y$ and $x$:

$$ y_t=a+b_1y_{t-1}+b_2y_{t-2}+c_1x_{t-1}+c_2x_{t-2}+u_t. $$

The test imposes the joint restriction

$$ H_0:c_1=c_2=0. $$

Rejection means that lagged $x$ adds predictive information after the included history of $y$ (Granger, 1969).

Restricted and unrestricted fits

Suppose the unrestricted residual sum of squares is 90. The restricted value is 100. There are two restrictions, 100 usable observations, and five unrestricted coefficients.

QuantityValue
RSS restricted100
RSS unrestricted90
Restrictions2
Residual degrees of freedom95

The comparison statistic is

$$ F=\frac{(100-90)/2}{90/95}=5.278. $$

Assumptions and implementation

The VAR should have a suitable lag order and stable dynamics. Innovations require an appropriate covariance model. Omitted relevant variables can change the predictive relation.

The result describes predictability. Structural causal interpretation needs additional restrictions. Software can report Wald, likelihood-ratio, or equation-level F forms with different finite-sample denominators.

The restricted information set sits inside the unrestricted set. Their forecast-error difference drives the test.

Interpretation and reporting

The statistic of $5.278$ measures how much the restricted equation loses fit after both lags of $x$ are removed. The restriction is joint. One lag can be weak while the pair still adds predictive information.

State the direction of the test. Evidence that $x$ predicts $y$ does not imply that $y$ predicts $x$. Report the variable set, lag order, usable time range, covariance estimator, and restriction list.

Granger causality is a prediction concept within the declared information set. An omitted series can create or remove the relation. Structural causal language requires further assumptions about shocks, timing, and intervention.

Reproducible implementation

Transform each series as required for stable VAR dynamics and align them on one time index. Select or declare the lag order before running the joint test. Keep the restricted and unrestricted equations on the same rows.

Estimate the unrestricted equation and test all coefficients on lagged $x$ together. Refit the restricted equation to verify the displayed RSS comparison when that form applies.

Check residual serial correlation and VAR stability. Repeat the reverse-direction test under its own restriction. Compare in-sample findings with out-of-sample forecast performance when prediction is the goal. Save lag definitions because software conventions can label the first usable observation differently (Lutkepohl, 2005).

Further reading

Granger defines the predictive concept (Granger, 1969). Lütkepohl develops testing in vector autoregressions (Lutkepohl, 2005).

Sources and further reading

  1. Clive W. J. Granger. 1969. “Investigating Causal Relations by Econometric Models and Cross-Spectral Methods.” Econometrica 37(3): 424–438. doi:10.2307/1912791.
  2. Helmut Lutkepohl. 2005. New Introduction to Multiple Time Series Analysis. Springer. doi:10.1007/978-3-540-27752-1.

Related reading

About this benchmark task

Method group
Time series
Software
Stata, R, and Python
Runs
360 runs, ten in each combination of model, software, prompt, and agency condition

Open every recorded run for this task.