r-econometrics by meleantonio/awesome-econ-ai-stuff
npx skills add https://github.com/meleantonio/awesome-econ-ai-stuff --skill r-econometrics此技能帮助经济学家在 R 中运行严谨的计量经济学分析,包括工具变量法、双重差分法和断点回归设计。它能生成带有适当诊断检验和稳健标准误的、可直接用于发表的代码。
在生成代码前,询问用户:
根据研究设计,生成 R 代码,该代码应:
fixest 包 - 用于面板数据,现代、快速且功能丰富modelsummary 或 etable 创建可直接用于发表的输出广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
始终包含:
# 1. 设置和包加载
# 2. 数据加载和准备
# 3. 描述性统计
# 4. 主回归设定
# 5. 稳健性检验
# 6. 可视化
# 7. 结果导出
包含解释以下内容的注释:
# ============================================
# 双重差分法分析
# ============================================
# 设置
library(tidyverse)
library(fixest)
library(modelsummary)
# 加载数据
df <- read_csv("data.csv")
# 准备处理变量
df <- df %>%
mutate(
post = year >= treatment_year,
treated = state %in% treatment_states,
treat_post = treated * post
)
# ----------------------------------------
# 主 DiD 设定
# ----------------------------------------
# 双向固定效应
did_model <- feols(
outcome ~ treat_post | state + year,
data = df,
cluster = ~state
)
# 查看结果
summary(did_model)
# ----------------------------------------
# 事件研究
# ----------------------------------------
# 创建相对时间变量
df <- df %>%
mutate(rel_time = year - treatment_year)
# 事件研究回归
event_study <- feols(
outcome ~ i(rel_time, treated, ref = -1) | state + year,
data = df,
cluster = ~state
)
# 绘制系数图
iplot(event_study,
main = "事件研究:对结果变量的影响",
xlab = "相对于处理年份的年份数")
# ----------------------------------------
# 稳健性检验:替代设定
# ----------------------------------------
# 不同的聚类方式
did_robust <- feols(
outcome ~ treat_post | state + year,
data = df,
cluster = ~state + year # 双向聚类
)
# ----------------------------------------
# 导出结果
# ----------------------------------------
modelsummary(
list("主回归" = did_model, "双向聚类" = did_robust),
stars = c('*' = 0.1, '**' = 0.05, '***' = 0.01),
output = "results/did_table.tex"
)
fixest - 快速固定效应估计modelsummary - 可直接用于发表的表格tidyverse - 数据操作ggplot2 - 可视化安装命令:
install.packages(c("fixest", "modelsummary", "tidyverse"))
feols 而非 lm每周安装量
75
代码仓库
GitHub 星标数
291
首次出现
2026年1月27日
安全审计
安装于
codex72
opencode70
gemini-cli68
github-copilot66
cursor63
kimi-cli60
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)Weekly Installs
75
Repository
GitHub Stars
291
First Seen
Jan 27, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex72
opencode70
gemini-cli68
github-copilot66
cursor63
kimi-cli60
Excel财务建模规范与xlsx文件处理指南:专业格式、零错误公式与数据分析
46,700 周安装