mcpbeat Sign in

R Empirical Finance Skill for Claude

> Conventions for writing empirical finance R code with data.table, fixest, arrow, and ggplot2. Use this skill whenever writing, reviewing, refactoring, or debugging R scripts for panel data, event studies, DiD, IV/2SLS, regressions, or data pipelines — even if the user just says "write some R code" or "clean this data."

2k tokens
context cost
the whole folder, loaded on every use
2
files
instructions only
0
copies elsewhere
how many repositories repackaged it
146
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/aspi6246/Claude-Code-Skills-for-Academics --skill r-empirical-finance

The instruction itself

9 sections, as written by the author

R Empirical Finance Code Standards

Package stack

Always prefer these packages unless the user specifies otherwise:

  • Data wrangling: dplyr or tidyverse (only data.table when required)
  • Regressions: fixest (feols, feglm) — never lm() for panel data
  • Large data I/O: arrow for Parquet files; never read.csv() for large data
  • Plotting: ggplot2 with clean minimal themes
  • Tables: etable() from fixest, or modelsummary
  • String handling: data.table patterns or base R; not stringr

Data loading

# Parquet — preferred format for large datasets
library(arrow)
library(data.table)

dt <- as.data.table(read_parquet("data/panel.parquet"))

# For partitioned Hive-style datasets (e.g., WellDatabase county files)
ds <- open_dataset("data/partitioned/", format = "parquet")
dt <- as.data.table(ds |> filter(year >= 2010) |> collect())

# CSV — only for small files, and always with data.table
dt <- fread("data/small_file.csv")

Never use read.csv() or read_csv(). Use fread() for CSV, read_parquet() for Parquet.

Panel data conventions

# Always set keys for panel data
setkey(dt, firm_id, year)

# Check for duplicates immediately after loading
stopifnot(!anyDuplicated(dt, by = c("firm_id", "year")))

# Or if duplicates are expected (e.g., multi-formation reporting), document why:
dupes <- dt[duplicated(dt, by = c("well_id", "month")), ]
message(sprintf("%d duplicate well-month observations (multi-formation)", nrow(dupes)))

Always verify:

  • Whether the panel is balanced or unbalanced
  • Whether duplicates exist and why
  • Whether merges are many-to-one or one-to-one

Regressions with fixest

library(fixest)

# Two-way fixed effects with clustered SEs
est <- feols(y ~ x1 + x2 | firm_id + year,
             data = dt, vcov = ~firm_id)

# Multiple outcomes in one call
est_multi <- feols(c(roa, tobinq) ~ treatment + controls | firm_id + year,
                   data = dt, vcov = ~firm_id)

# Staggered DiD with Sun & Abraham (2021)
est_sa <- feols(y ~ sunab(treatment_year, year) | firm_id + year,
                data = dt, vcov = ~firm_id)

# IV / 2SLS
est_iv <- feols(y ~ x_control | firm_id + year | x_endog ~ z_instrument,
                data = dt, vcov = ~firm_id)

# Event study
est_es <- feols(y ~ i(rel_year, ref = -1) | firm_id + year,
                data = dt, vcov = ~firm_id)
iplot(est_es, main = "Event Study")

Always cluster standard errors. The default for panel data is clustering at the

unit level (firm_id). Two-way clustering (firm + year) is sometimes appropriate

for short panels — flag this choice explicitly.

Results output

# Quick inspection
etable(est1, est2, est3, vcov = "cluster")

# Publication-quality table
etable(est1, est2, est3,
       vcov = "cluster",
       dict = c(x1 = "Treatment", x2 = "Size", x3 = "Leverage"),
       tex = TRUE,
       file = "output/tables/main_results.tex")

# Summary statistics
dt[, .(mean = mean(y, na.rm = TRUE),
       sd = sd(y, na.rm = TRUE),
       p25 = quantile(y, 0.25, na.rm = TRUE),
       median = median(y, na.rm = TRUE),
       p75 = quantile(y, 0.75, na.rm = TRUE),
       n = .N),
   by = group_var]

Plotting

library(ggplot2)

# Preferred theme
theme_clean <- theme_minimal() +
  theme(
    panel.grid.minor = element_blank(),
    legend.position = "bottom",
    plot.title = element_text(face = "bold", size = 12),
    axis.title = element_text(size = 10)
  )

# Always label axes, cite data sources in captions
ggplot(dt, aes(x = year, y = mean_y)) +
  geom_line() +
  labs(title = "Title Here",
       x = "Year", y = "Outcome Variable",
       caption = "Source: WRDS/Compustat") +
  theme_clean

Common gotchas — always flag these

  • Using lm() on panel data (no fixed effects absorption, slow)
  • Missing vcov = ~firm_id on panel regressions (defaults to iid)
  • Using read.csv() on files > 50MB (suggest fread() or arrow)
  • Hardcoded file paths (should be relative to project root)
  • Missing duplicate checks after merges or data loading
  • na.rm = TRUE missing on summary statistics
  • For DiD: not checking parallel trends pre-treatment
  • For IV: not reporting the first stage F-statistic

File and folder conventions

project/
├── data/
│   ├── raw/          # Never modify raw data
│   └── processed/    # Cleaned, analysis-ready datasets
├── code/
│   ├── 01_clean.R
│   ├── 02_merge.R
│   ├── 03_analysis.R
│   └── 04_figures.R
├── output/
│   ├── tables/
│   └── figures/
└── README.md

Number scripts in execution order. Never modify raw data in place — always

write cleaned data to a separate location.

For more detailed fixest patterns and advanced usage, see references/fixest-patterns.md.

Other skills for the same job

different authors, same section of the catalogue
Webapp Testing
by anthropics
vendor ×12

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

6k tokens scripts
Finishing A Development Branch
by ZhanlinCui
×7

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup

1k tokens
Test Driven Development
by w95
×7

Use when implementing any feature or bugfix, before writing implementation code

2k tokens
Systematic Debugging
by ratacat
×7

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes

10k tokens scripts
Verification Before Completion
by ZhanlinCui
×6

Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always

1k tokens
Backtest Expert
by BaggaT236
×3

Expert guidance for systematic backtesting of trading strategies. Use when developing, testing, stress-testing, or validating quantitative trading strategies. Covers "beating ideas to death" methodology, parameter robustness testing, slippage modeling, bias prevention, and interpreting backtest results. Applicable when user asks about backtesting, strategy validation, robustness testing, avoiding overfitting, or systematic trading development.

15k tokens scripts
Adaptyv
by christophacham
×3

Cloud laboratory platform for automated protein testing and validation. Use when designing proteins and needing experimental validation including binding assays, expression testing, thermostability measurements, enzyme activity assays, or protein sequence optimization. Also use for submitting experiments via API, tracking experiment status, downloading results, optimizing protein sequences for better expression using computational tools (NetSolP, SoluProt, SolubleMPNN, ESM), or managing protein design workflows with wet-lab validation.

16k tokens
Aeon
by christophacham
×3

This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.

19k tokens

How to use it

Copy the folder

Take aspi6246/r-empirical-finance from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.