R Econometrics logo

R Econometrics

CommunityPopular
brycewang-stanford
r-econometrics

Run IV, DiD, and RDD analyses in R with proper diagnostics

Overview

Publisherbrycewang-stanford
RepositoryAuto-Empirical-Research-Skills
Skill namer-econometrics
Stars
3.8K
Forks
479
Bundled files
1
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by brycewang-stanford on GitHub. Read the source before you install it.

Installation

Install the R Econometrics AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills.git /tmp/Auto-Empirical-Research-Skills
mkdir -p .claude/skills
cp -r /tmp/Auto-Empirical-Research-Skills/skills/09-meleantonio-awesome-econ-ai-stuff/_skills/analysis/r-econometrics .claude/skills/r-econometrics
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable R Econometrics in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads R Econometrics on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so R Econometrics is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

R Econometrics

Purpose

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.

When to Use

  • Running causal inference analyses
  • Estimating treatment effects with panel data
  • Creating publication-ready regression tables
  • Implementing modern econometric methods (two-way fixed effects, event studies)

Instructions

Step 1: Understand the Research Design

Before generating code, ask the user:

  1. What is your identification strategy? (IV, DiD, RDD, or simple regression)
  2. What is the unit of observation? (individual, firm, country-year, etc.)
  3. What fixed effects do you need? (entity, time, two-way)
  4. How should standard errors be clustered?

Step 2: Generate Analysis Code

Based on the research design, generate R code that:

  1. Uses the fixest package - Modern, fast, and feature-rich for panel data
  2. Includes proper diagnostics:
    • For IV: First-stage F-statistics, weak instrument tests
    • For DiD: Parallel trends visualization, event study plots
    • For RDD: Bandwidth selection, density tests
  3. Uses robust/clustered standard errors appropriate for the data structure
  4. Creates publication-ready output using modelsummary or etable

Step 3: Structure the Output

Always 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

Step 4: Add Documentation

Include comments explaining:

  • Why each specification choice was made
  • Interpretation of key coefficients
  • Limitations and assumptions

Example Prompts

  • "Run a DiD analysis with state and year fixed effects, clustering at the state level"
  • "Estimate the effect of X on Y using Z as an instrument"
  • "Create an event study plot showing treatment effects by year"
  • "Run a sharp RDD with optimal bandwidth selection"

Example Output

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"
)

Requirements

Software

  • R 4.0+

Packages

  • fixest - Fast fixed effects estimation
  • modelsummary - Publication-ready tables
  • tidyverse - Data manipulation
  • ggplot2 - Visualization

Install with:

r
install.packages(c("fixest", "modelsummary", "tidyverse"))

Best Practices

  1. Always cluster standard errors at the level of treatment assignment
  2. Run pre-trend tests for DiD designs
  3. Report first-stage F-statistics for IV (should be > 10)
  4. Use feols over lm for panel data (faster and more features)
  5. Document all specification choices in your code comments

Common Pitfalls

  • ❌ Not clustering standard errors at the right level
  • ❌ Ignoring weak instruments in IV estimation
  • ❌ Using TWFE with staggered treatment timing (use did or sunab() instead)
  • ❌ Not reporting robustness checks

References

Changelog

v1.0.0

  • Initial release with IV, DiD, RDD support

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the R Econometrics AI skill do?

Run IV, DiD, and RDD analyses in R with proper diagnostics

Why use R Econometrics on TypingMind?

Because you install it once and use it with any model. R Econometrics is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install R Econometrics in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills/tree/main/skills/09-meleantonio-awesome-econ-ai-stuff/_skills/analysis/r-econometrics. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use R Econometrics?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with R Econometrics?

As many as you like. As long as a model supports skills, you can use R Econometrics with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the R Econometrics AI skill free?

It is published on GitHub by brycewang-stanford. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇