skills/14-luischanci-claude-code-research-starter/dot-claude/skills/econometrics-r/SKILL.md
R-based econometric analysis for academic research. Use when writing R code for panel data, difference-in-differences, instrumental variables, spatial econometrics, or regression analysis. Covers data.table, fixest, sf, modelsummary, and publication-ready outputs.
npx skillsauth add brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research econometrics-rInstall 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.
library(data.table) # Data manipulation
library(fixest) # Fixed effects estimation
library(modelsummary) # Regression tables
library(ggplot2) # Visualization
library(sf) # Spatial data
library(here) # Project paths
# Read and assign
dt <- fread(here("data", "raw", "file.csv"))
# Common operations
dt[, new_var := old_var * 100] # Create variable
dt[, mean_y := mean(y, na.rm = TRUE), by = group] # Group operations
dt[year >= 2000 & treated == 1] # Filter
dt[, .(mean_y = mean(y), n = .N), by = group] # Summarize
dt[other_dt, on = .(id, year)] # Merge
# Lag/lead within groups
setorder(dt, id, year)
dt[, lag_y := shift(y, 1), by = id]
dt[, lead_y := shift(y, -1), by = id]
# Two-way fixed effects
est1 <- feols(y ~ treatment + controls | id + year, data = dt)
# Clustered standard errors (default: fixed effect groups)
est2 <- feols(y ~ treatment | id + year, data = dt, cluster = ~state)
# IV regression
est3 <- feols(y ~ controls | id + year | endog ~ instrument, data = dt)
# Classic 2x2 DiD
est_did <- feols(y ~ treated:post | id + year, data = dt)
# Event study / dynamic effects
dt[, rel_time := year - treatment_year]
dt[, rel_time := fifelse(is.na(rel_time), -1000, rel_time)] # Never-treated
est_es <- feols(y ~ i(rel_time, ref = -1) | id + year, data = dt)
iplot(est_es) # Coefficient plot
# Sun-Abraham (requires cohort variable)
est_sa <- feols(y ~ sunab(cohort, year) | id + year, data = dt)
# Multiple estimators comparison
library(did) # Callaway-Sant'Anna
models <- list(
"OLS" = est1,
"With FE" = est2,
"IV" = est3
)
modelsummary(models,
stars = c('*' = 0.1, '**' = 0.05, '***' = 0.01),
coef_omit = "Intercept",
gof_omit = "AIC|BIC|Log",
output = here("output", "tables", "main_results.tex")
)
etable(est1, est2, est3,
se.below = TRUE,
keep = "treatment",
fitstat = c("n", "r2", "fe"),
tex = TRUE,
file = here("output", "tables", "results.tex")
)
# example
etable(
m1.suit, m2.suit,
dict = c(
'gruter_1' = 'Gruter Suitability 1',
'gruter_2' = 'Gruter Suitability 2',
'gruter_3' = 'Gruter Suitability 3',
'gruter_4' = 'Gruter Suitability 4',
'area_ha' = 'Orchard Size (ha)',
'yield' = 'Yield (kg/ha), 2023'
),
extralines = list(
'_Average yield (kg/ha)' = c(
round(mean(yields[area_ha > 1 & year == 2023, yield], na.rm = TRUE), 2),
round(mean(yields[area_ha > 1 & year == 2023, yield], na.rm = TRUE), 2)
),
'_Average orchard size (ha)' = c(
round(mean(yields[area_ha > 1 & year == 2023, area_ha], na.rm = TRUE), 2),
round(mean(yields[area_ha > 1 & year == 2023, area_ha], na.rm = TRUE), 2)
)
),
tex = TRUE,
style.tex = style.tex('aer'),
digits = 3,
depvar = TRUE
)
coef_data <- broom::tidy(est_es, conf.int = TRUE)
ggplot(coef_data, aes(x = term, y = estimate)) +
geom_point() +
geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.2) +
geom_hline(yintercept = 0, linetype = "dashed") +
theme_bw() +
labs(x = "Period", y = "Coefficient")
ggsave(here("output", "figures", "event_study.pdf"), width = 8, height = 5)
library(sf)
map_data <- st_read(here("data", "raw", "shapefile.shp"))
map_data <- merge(map_data, results_dt, by = "region_id")
ggplot(map_data) +
geom_sf(aes(fill = estimate), color = "white", size = 0.1) +
scale_fill_viridis_c() +
theme_void()
library(spdep)
library(spatialreg)
# Create spatial weights
coords <- st_coordinates(st_centroid(map_data))
nb <- knn2nb(knearneigh(coords, k = 5))
W <- nb2listw(nb, style = "W")
# Spatial lag model
est_sar <- lagsarlm(y ~ x1 + x2, data = map_data, listw = W)
# Spatial error model
est_sem <- errorsarlm(y ~ x1 + x2, data = map_data, listw = W)
library(grf) # Generalized random forests
# Causal forest
cf <- causal_forest(
X = as.matrix(dt[, .(x1, x2, x3)]),
Y = dt$y,
W = dt$treatment
)
# Treatment effects
ate <- average_treatment_effect(cf)
cate <- predict(cf)$predictions
set.seed(12345)feols(..., lean = TRUE) for large datasetsfwrite() for fast CSV outputtools
Recommend AND run open-source AI tools, agents, Claude Code / Codex skills, and MCP servers for any stage of a literature review — searching, reading, extracting, synthesizing, screening, citation-checking, and paper writing. Use when the user asks "what tool should I use to..." OR "install/run/use <tool> to ..." for research/lit-review work: automating a survey or related-work section, PDF→Markdown extraction for LLMs (MinerU/marker/docling), PRISMA / systematic review (ASReview), citation-backed Q&A over PDFs (PaperQA2), wiring papers into Claude/Cursor via MCP (arxiv/paper-search/zotero servers), or chatting with a Zotero library. Ships a launcher (scripts/litrun.py) that installs each tool in an isolated venv and runs it. Curated catalog of 70+ vetted projects. 支持中英文(用于「文献综述工具选型」与「一键安装/运行」)。
development
Route empirical-research requests through the Auto-Empirical Research Skills catalog when this whole repository is installed as one skill in Codex, CodeBuddy, Claude Code, or another IDE. Use to choose and load the right vendored AERS skill for causal inference, econometrics, replication, data acquisition, manuscript writing, peer review and referee responses, citation checking, de-AIGC editing, or full empirical-paper workflows without reading the entire repository at once.
documentation
Use when the project collects primary data or runs a field, lab, or survey experiment, before the intervention begins — write the pre-analysis plan, size the sample from a power calculation, and register with the AEA RCT Registry. Apply after the design is chosen in aer-identification and before any outcome data are seen.
tools
Guide economists to authoritative data sources with explicit, confirmed data specifications before retrieval; interfaces with Playwright MCP to navigate portals and extract real data, not articles about data.