Econ detrending correlation

From XuShuwenn/RedAct · View interactive version

Econ detrending correlation is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Apply Hodrick-Prescott filter to detrend economic time series and calculate Pearson correlation between consumption and investment.

How to use this skill

Skill file

Economic Time Series Detrending and Correlation

When to Use

Input Files

Key Steps

  1. Inspect each input workbook first with spreadsheet-aware tools: print sheet names, column labels, and representative top/middle/bottom rows before coding against assumed headers or row formats; identify the actual header row, where annual data begins, the correct Total/value column, and where quarterly/footer sections start
  2. Extract Personal Consumption Expenditures (Total, column 1) and PFI (Total, column 1) from their ERP tables separately

2a. For each ERP workbook, identify the year/label column and numeric value column from that workbook itself; do not reuse row offsets, header positions, or footer boundaries from the other ERP file.

2b. Print a small sample of extracted annual year→value pairs for each series before merging so wrong-row or wrong-column extraction is caught early.

  1. Build independent year→value mappings for each series, then merge by year; do not assume matching row numbers across the two files

3a. Normalize extracted year labels before filtering or merging: trim whitespace/trailing punctuation so labels like 1973. parse to the intended year instead of being silently dropped.

3b. After merging, print the overlapping year span and observation count, plus a few first/last merged rows, before proceeding.

  1. Handle quarterly data at end of tables by inspecting the bottom rows first; for 2024, statefully track the active year, enumerate every matched 2024 quarter row from that active-year block (including inherited labels like II./III p. after 2024: I.), stop when notes/source/footer text begins, and compute the annual 2024 value as the mean of all available 2024 quarters shown in the source table
  2. Validate extraction results before proceeding: ensure annual observations are non-empty, years are in expected order, and 2024 handling did not accidentally pull quarters from earlier years, miss available quarters, or remove the series
  3. Inspect /root/CPI.xlsx with targeted output (sheet names, exact column names, and sample rows), then confirm the actual year column, CPI/deflator column, and unit/scaling before deflating; if the workbook already provides a target-year deflator/ratio, use that column directly rather than rebuilding it from a guessed schema
  4. Before HP filtering, verify the CPI-aligned real consumption and real investment series use the identical final year list, and print a short diagnostic showing overlapping years, sample real values, and the exact deflation formula used
  5. Apply the required transformation order exactly: nominal → real via CPI → natural log → Hodrick-Prescott filter with λ=100
  6. Compute Pearson correlation between the two cyclical components
  7. Round result to 5 decimal places
  8. Prefer one reproducible Python script for the full pipeline: inspect workbooks, extract both nominal series, annualize 2024 from quarters, merge by year with CPI, deflate, log, HP-filter, correlate, write /root/answer.txt, then read it back
  9. Before concluding, rerun the final script end-to-end without error, explicitly print the extracted 2024 quarter labels/values and quarter counts for both series, the overlap year range/count, the final correlation, and read back /root/answer.txt to confirm the saved value was freshly written and matches the computed value

HP Filter

Validation Checks

Validation Checks

Output Format

Single number to /root/answer.txt

Before trusting /root/answer.txt, verify the computation ran end-to-end: confirm deflation, HP filtering, and correlation steps executed successfully and the script exited normally. If output is truncated or diagnostics stop early, rerun or inspect the error instead of treating an existing answer file as success.

Tips

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.