skills/43-wentorai-research-plugins/skills/analysis/econometrics/time-series-guide/SKILL.md
Apply ARIMA, VAR, cointegration, and time series econometric methods
npx skillsauth add brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research time-series-guideInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A skill for applying time series econometric methods including ARIMA modeling, VAR systems, cointegration analysis, and unit root tests. Covers stationarity concepts, model selection, forecasting, and diagnostic checking for economic and financial data.
A time series is stationary when its statistical properties (mean, variance, autocorrelation) do not change over time. Most econometric methods require stationarity. Non-stationary series can produce spurious regressions.
from statsmodels.tsa.stattools import adfuller, kpss
import pandas as pd
def test_stationarity(series: pd.Series, name: str = "Series") -> dict:
"""
Test for stationarity using ADF and KPSS tests.
Args:
series: Time series data
name: Label for the series
"""
# Augmented Dickey-Fuller test
# H0: Unit root exists (non-stationary)
adf_result = adfuller(series.dropna(), autolag="AIC")
# KPSS test
# H0: Series is stationary
kpss_result = kpss(series.dropna(), regression="c", nlags="auto")
return {
"series": name,
"adf": {
"statistic": adf_result[0],
"p_value": adf_result[1],
"lags_used": adf_result[2],
"conclusion": (
"Stationary (reject unit root)"
if adf_result[1] < 0.05
else "Non-stationary (fail to reject unit root)"
)
},
"kpss": {
"statistic": kpss_result[0],
"p_value": kpss_result[1],
"conclusion": (
"Non-stationary (reject stationarity)"
if kpss_result[1] < 0.05
else "Stationary (fail to reject stationarity)"
)
}
}
Method 1: Differencing
y_diff = y_t - y_{t-1} (first difference)
y_diff2 = delta(y_diff) (second difference, rarely needed)
Method 2: Log transformation + differencing
y_log = log(y_t) (stabilizes variance)
y_return = log(y_t) - log(y_{t-1}) (log returns)
Method 3: Detrending
Subtract a fitted trend (linear, polynomial, or HP filter)
ARIMA(p, d, q):
p = order of autoregressive (AR) component
d = degree of differencing
q = order of moving average (MA) component
SARIMA(p, d, q)(P, D, Q, s):
Seasonal extension with period s
P, D, Q = seasonal AR, differencing, MA orders
from statsmodels.tsa.arima.model import ARIMA
import numpy as np
def fit_arima(series: pd.Series, order: tuple = None) -> dict:
"""
Fit an ARIMA model, optionally using auto-selection.
Args:
series: Time series data
order: (p, d, q) tuple; if None, uses AIC-based selection
"""
if order is None:
# Grid search over common orders
best_aic = np.inf
best_order = (0, 0, 0)
for p in range(4):
for d in range(3):
for q in range(4):
try:
model = ARIMA(series, order=(p, d, q))
result = model.fit()
if result.aic < best_aic:
best_aic = result.aic
best_order = (p, d, q)
except Exception:
continue
order = best_order
model = ARIMA(series, order=order)
result = model.fit()
return {
"order": order,
"aic": result.aic,
"bic": result.bic,
"coefficients": dict(zip(result.param_names, result.params)),
"residual_diagnostics": {
"ljung_box_p": float(
result.test_serial_correlation("ljungbox", lags=[10])[0]["lb_pvalue"].iloc[0]
)
}
}
from statsmodels.tsa.api import VAR
def fit_var_model(data: pd.DataFrame, maxlags: int = 12) -> dict:
"""
Fit a VAR model to multivariate time series data.
Args:
data: DataFrame with multiple time series columns
maxlags: Maximum lag order to consider
"""
model = VAR(data)
# Select lag order by information criteria
lag_selection = model.select_order(maxlags=maxlags)
optimal_lag = lag_selection.aic
result = model.fit(optimal_lag)
return {
"lag_order": optimal_lag,
"aic": result.aic,
"variables": list(data.columns),
"granger_causality": "Use result.test_causality() for pairwise tests",
"irf": "Use result.irf(periods=20) for impulse response functions"
}
Granger causality tests whether past values of variable X improve forecasts of variable Y beyond what past values of Y alone provide. It is a test of predictive precedence, not true causation.
from statsmodels.tsa.stattools import coint
from statsmodels.tsa.vector_ar.vecm import coint_johansen
def test_cointegration(y1: pd.Series, y2: pd.Series) -> dict:
"""
Test for cointegration between two series.
Args:
y1: First time series
y2: Second time series
"""
# Engle-Granger two-step test
eg_stat, eg_pvalue, eg_crit = coint(y1, y2)
return {
"engle_granger": {
"statistic": eg_stat,
"p_value": eg_pvalue,
"conclusion": (
"Cointegrated" if eg_pvalue < 0.05
else "Not cointegrated"
)
},
"interpretation": (
"If cointegrated, these series share a long-run equilibrium "
"relationship. Use a Vector Error Correction Model (VECM) "
"rather than a VAR in differences."
)
}
1. Residual autocorrelation: Ljung-Box test (should be non-significant)
2. Residual normality: Jarque-Bera test or Q-Q plot
3. Heteroskedasticity: ARCH-LM test for conditional heteroskedasticity
4. Stability: Check that AR roots lie inside the unit circle
5. Forecast accuracy: Out-of-sample RMSE, MAE, MAPE
6. Information criteria: Compare AIC/BIC across candidate models
Report all diagnostic results in your paper. Reviewers expect evidence that residuals are well-behaved and that the chosen model specification is justified by information criteria and domain knowledge.
development
Conduct rigorous thematic analysis (TA) of qualitative data following Braun and Clarke's (2006) six-phase framework. Use whenever the user mentions 'thematic analysis', 'TA', 'Braun and Clarke', 'qualitative coding', 'identifying themes', or asks for help analysing interviews, focus groups, open-ended survey responses, or transcripts to identify patterns. Also trigger for questions about inductive vs theoretical coding, semantic vs latent themes, essentialist vs constructionist epistemology, building a thematic map, or writing up a qualitative findings section. Covers all six phases, the four upfront analytic decisions, the 15-point quality checklist, and the five common pitfalls. Produces a Word document write-up and an annotated thematic map. Does NOT cover IPA, grounded theory, discourse analysis, conversation analysis, or narrative analysis — use a different method for those.
development
Guide users through writing a systematic literature review (SLR) following the PRISMA 2020 framework. Use this skill whenever the user mentions 'systematic review', 'systematic literature review', 'SLR', 'PRISMA', 'PRISMA 2020', 'PRISMA flow diagram', 'PRISMA checklist', or asks for help writing, structuring, or auditing a literature review that follows reporting guidelines. Also trigger when the user asks about inclusion/exclusion criteria for a review, search strategies for databases like Scopus/WoS/PubMed, study selection processes, risk of bias assessment, or narrative synthesis for a review paper. This skill covers the full PRISMA 2020 checklist (27 items), produces a Word document manuscript in strict journal article format, generates an annotated PRISMA flow diagram, and enforces APA 7th Edition referencing throughout. It does NOT cover meta-analysis or statistical pooling. By Chuah Kee Man.
testing
Performs placebo-in-time sensitivity analysis with hierarchical null model and optional Bayesian assurance. Use when checking model robustness, verifying lack of pre-intervention effects, or estimating study power.
data-ai
Fit, summarize, plot, and interpret a chosen CausalPy experiment. Use after the causal method has been selected, including when configuring PyMC/sklearn models and scale-aware custom priors.