一键导入
一键导入
| name | r-econometrics |
| description | Run IV, DiD, and RDD analyses in R with proper diagnostics |
| workflow_stage | analysis |
| compatibility | ["claude-code","cursor","codex","gemini-cli"] |
| author | Awesome Econ AI Community |
| version | 1.0.0 |
| tags | ["R","econometrics","causal-inference","fixest","regression"] |
This skill helps economists run rigorous econometric analyses in R, including Instrumental Variables (IV), Difference-in-Differences (DiD), and Regression Discontinuity Design (RDD). It generates publication-ready code with proper diagnostics and robust standard errors.
Before generating code, ask the user:
Based on the research design, generate R code that:
fixest package - Modern, fast, and feature-rich for panel datamodelsummary or etableAlways include:
# 1. Setup and packages
# 2. Data loading and preparation
# 3. Descriptive statistics
# 4. Main specification
# 5. Robustness checks
# 6. Visualization
# 7. Export results
Include comments explaining:
# ============================================
# Difference-in-Differences Analysis
# ============================================
# Setup
library(tidyverse)
library(fixest)
library(modelsummary)
# Load data
df <- read_csv("data.csv")
# Prepare treatment variable
df <- df %>%
mutate(
post = year >= treatment_year,
treated = state %in% treatment_states,
treat_post = treated * post
)
# ----------------------------------------
# Main DiD Specification
# ----------------------------------------
# Two-way fixed effects
did_model <- feols(
outcome ~ treat_post | state + year,
data = df,
cluster = ~state
)
# View results
summary(did_model)
# ----------------------------------------
# Event Study
# ----------------------------------------
# Create relative time variable
df <- df %>%
mutate(rel_time = year - treatment_year)
# Event study regression
event_study <- feols(
outcome ~ i(rel_time, treated, ref = -1) | state + year,
data = df,
cluster = ~state
)
# Plot coefficients
iplot(event_study,
main = "Event Study: Effect on Outcome",
xlab = "Years Relative to Treatment")
# ----------------------------------------
# Robustness: Alternative Specifications
# ----------------------------------------
# Different clustering
did_robust <- feols(
outcome ~ treat_post | state + year,
data = df,
cluster = ~state + year # Two-way clustering
)
# ----------------------------------------
# Export Results
# ----------------------------------------
modelsummary(
list("Main" = did_model, "Two-way Cluster" = did_robust),
stars = c('*' = 0.1, '**' = 0.05, '***' = 0.01),
output = "results/did_table.tex"
)
fixest - Fast fixed effects estimationmodelsummary - Publication-ready tablestidyverse - Data manipulationggplot2 - VisualizationInstall with:
install.packages(c("fixest", "modelsummary", "tidyverse"))
feols over lm for panel data (faster and more features)did or sunab() instead)Simplify and clean up code after changes are complete. Reduces complexity, improves readability, and ensures consistency.
Commit changes, push to remote, and create a pull request. Use for completing features or fixes ready for review.
Implements the Spec-Driven Development lifecycle (Intent, Requirements, Design, Tasks, Build) for structured feature development. Use when the user wants to scaffold a new feature spec, generate EARS requirements, create a technical design, break work into tasks, or check spec status. Trigger on keywords: sdd, spec-driven, ears requirements, feature spec.
Find and fix technical debt including duplicated code, dead code, outdated patterns, and code smells. Run at the end of sessions to clean up.
Build and solve Walrasian general equilibrium models with theory derivations and Julia computation
Panel data analysis with Python using linearmodels and pandas.