Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Run IV, DiD, and RDD analyses in R with proper diagnostics
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-04 | ✓→✓ | = Same ✓ | 45% | 0% |
| case-05 | ✓→✓ | = Same ✓ | 19% | 0% |
| case-06 | ✓→✓ | = Same ✓ | 70% | 0% |
| case-07 | ✓→✓ | = Same ✓ | 38% | 0% |
| case-08 | ✓→✓ | = Same ✓ | 29% | 0% |
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:
r# 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:
r# ============================================ # 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:
rinstall.packages(c("fixest", "modelsummary", "tidyverse"))
feols over lm for panel data (faster and more features)did or sunab() instead)Other measured skills in the registry, with their headline benchmark lift.