Causal
ai-analyst-lab/ai-analyst
Causal inference toolkit for when experiments are not possible: estimate treatment effects from observational data with assumption checks and mandatory caveats.
经济金融实证方法设计。根据研究想法和REFINEDDESIGN.md,生成完整的实证研究设计方案,覆盖识别策略选择、样本构建、变量定义、稳健性检验清单和内生性处理方案。
$ npx skills add csmar432/finai-research --skill fin-experiment-design -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install csmar432/finai-research fin-experiment-design --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ git clone --depth 1 https://github.com/csmar432/finai-research.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/fin-experiment-design .claude/skills/fin-experiment-design && rm -rf skills-srcUse ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.
Claude Code skills documentation · loads skills from .claude/skills/
Install the "fin-experiment-design" agent skill from https://github.com/csmar432/finai-research/tree/main/.agents/skills/fin-experiment-design into .claude/skills/fin-experiment-design/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "fin-experiment-design", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/csmar432/finai-research/tree/main/.agents/skills/fin-experiment-designType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add csmar432/finai-research --skill fin-experiment-design -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install csmar432/finai-research fin-experiment-design --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/csmar432/finai-research.git skills-src && mkdir -p .agents/skills && cp -r skills-src/.agents/skills/fin-experiment-design .agents/skills/fin-experiment-design && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "fin-experiment-design" agent skill from https://github.com/csmar432/finai-research/tree/main/.agents/skills/fin-experiment-design into .agents/skills/fin-experiment-design/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "fin-experiment-design", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add csmar432/finai-research --skill fin-experiment-design -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install csmar432/finai-research fin-experiment-design --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/csmar432/finai-research.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/.agents/skills/fin-experiment-design .cursor/skills/fin-experiment-design && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "fin-experiment-design" agent skill from https://github.com/csmar432/finai-research/tree/main/.agents/skills/fin-experiment-design into .cursor/skills/fin-experiment-design/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "fin-experiment-design", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/csmar432/finai-research.git --path .agents/skills/fin-experiment-design--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add csmar432/finai-research --skill fin-experiment-design -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install csmar432/finai-research fin-experiment-design --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/csmar432/finai-research.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/.agents/skills/fin-experiment-design .gemini/skills/fin-experiment-design && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "fin-experiment-design" agent skill from https://github.com/csmar432/finai-research/tree/main/.agents/skills/fin-experiment-design into .gemini/skills/fin-experiment-design/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "fin-experiment-design", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install csmar432/finai-research fin-experiment-designInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add csmar432/finai-research --skill fin-experiment-design -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/csmar432/finai-research.git skills-src && mkdir -p .github/skills && cp -r skills-src/.agents/skills/fin-experiment-design .github/skills/fin-experiment-design && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "fin-experiment-design" agent skill from https://github.com/csmar432/finai-research/tree/main/.agents/skills/fin-experiment-design into .github/skills/fin-experiment-design/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "fin-experiment-design", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add csmar432/finai-research --skill fin-experiment-design -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install csmar432/finai-research fin-experiment-design --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/csmar432/finai-research.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/.agents/skills/fin-experiment-design .opencode/skills/fin-experiment-design && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "fin-experiment-design" agent skill from https://github.com/csmar432/finai-research/tree/main/.agents/skills/fin-experiment-design into .opencode/skills/fin-experiment-design/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "fin-experiment-design", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
fin-experiment-design经济金融实证方法设计。根据研究想法和REFINEDDESIGN.md,生成完整的实证研究设计方案,覆盖识别策略选择、样本构建、变量定义、稳健性检验清单和内生性处理方案。
Fin Experiment Design is an agent skill from csmar432/finai-research. 经济金融实证方法设计。根据研究想法和REFINEDDESIGN.md,生成完整的实证研究设计方案,覆盖识别策略选择、样本构建、变量定义、稳健性检验清单和内生性处理方案。
Its SKILL.md is about 4.2k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.
It sits in Research & Science, covering Experimental design, Design tokens and Econometrics and empirical research. The repository describes itself as: Evidence-first AI workflow for economic and financial research: literature → identification → data → econometrics → verifiable LaTeX. 43 data sources, 58 method modules, 18 AI… The licence is MIT.
4 steps, taken from the step headings in SKILL.md.
Read from SKILL.md and the folder at commit 47eebb7. It shows what the files ask for, not the result of running them.
Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.
From allowed-tools in the SKILL.md frontmatter.
Shell commands in SKILL.md call:
pythonFrom the folder's file list and the shell code blocks in SKILL.md.
No URLs in SKILL.md.
From URLs in SKILL.md, links to its own repository left out.
Names no API keys, tokens, secrets or passwords.
From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
Fin Experiment Design loads about 4.2k tokens when it runs. Until then it costs about 27 tokens; SKILL.md has 575 words of instructions outside code blocks.
Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.
The automated check found no risky patterns in SKILL.md.
Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.
The full file from csmar432/finai-research at commit 47eebb7, republished under its MIT licence (© csmar432). 575 words, ~4,203 tokens.
.claude/skills/fin-experiment-design/SKILL.md (or your agent's skills folder).将研究想法细化为完整、可执行的实证研究设计。
所有文件输出到 output/fin-refinement/ 目录:
| 文件 | 说明 | 优先级 |
|---|---|---|
REFINED_DESIGN.md | 核心研究设计文档(最重要) | 必须 |
EXPERIMENT_PLAN.md | 详细实验执行计划 | 必须 |
VARIABLE_DEFINITIONS.md | 变量定义表 | 必须 |
ROBUSTNESS_PLAN.md | 稳健性检验方案 | 必须 |
ENDOGENEITY_PLAN.md | 内生性处理方案 | 必须 |
EXECUTION_CHECKLIST.md | 实验执行检查清单 | 必须 |
empirical_package.json | 实证包契约(表台阶 / 控制职务 / 机制 / 图门) | 必须 |
选控制、写机制前先走十问,不要抄例 JSON 的渠道名:
python -m scripts.core.empirical_package questions
python -m scripts.core.empirical_package scaffold --mode core --unit firm
python -m scripts.core.empirical_package audit output/fin-refinement/empirical_package.json实证轨跑一遍就能把能算的格填上(结构事实 / 逐步 / 更紧 / 样本流;机制须自己点名渠道):
python -m scripts.research_framework.enhanced_pipeline --topic "..." --mechanism 渠道列名empirical_package.json 最低要求:y_construct / x_construct、每件控制的 variable_jobs(中文 table_row + 接到本题 Y 的 job + 非贴纸 basis)、黄金八格(缺格写 dropped 理由)、政策 DID 还要独立于电池的 mechanism_channels(≥2 条且不是本题 Y)与 figure_gate。mechanism_methods 按推断家族计数(sobel+bootstrap 只算一种)。政策 DID 不得 dropped: mechanism。core 包须有 inference 块(交错估计量进基准表;处理簇 <50 用野靴带或随机化推断;事前趋势敏感)。交稿是合取:主栏显著 ∧ 控制有职务 ∧ 活机制表 ∧ 图干净 ∧ 能复述的 story 页。H1 必须是主发现,禁止写「H1 被拒绝」/ “H1 is rejected”。
读取以下文件(按优先级):
output/fin-ideas/IDEA_REPORT.md — 选定研究想法output/fin-novelty/NOVELTY_REPORT.md — 新颖性验证output/fin-literature/LIT_REVIEW.md — 文献综述FIN_BRIEF.md — 研究简报output/fin-refinement/REFINED_DESIGN.md — 如已存在,读取并更新# scripts/research_framework/modern_did.py
from modern_did import ModernDiDEngine, DiDEstimationResult
# scripts/research_framework/robustness_runner.py
from robustness_runner import RobustnessRunner, RobustnessReport
# scripts/research_framework/iv_panel.py
from iv_panel import IVPanel
# scripts/research_framework/rdd.py
from rdd import RDDEngine⚠️ Checkpoint: 策略选择后必须向用户展示决策树结果,解释为何选择该策略。
样本是否包含处理组/对照组?
│
├── 是 → 政策/处理时点是否单一?
│ ├── 是 → 经典 2×2 DID
│ │ ├── 单一处理队列 → 标准 DID (Angrist & Pischke 2009)
│ │ └── 多处理队列 → Callaway-SantAnna (QJE 2021) [推荐]
│ │ 或 Sun-Abraham (REStud 2021)
│ │ 或 Borusyak-Jaravel-Spinks (REStud 2024)
│ │ 或 Gardner (2022) shock-free
│ │
│ └── 否 → 合成控制法 (Abadie et al. 2010)
│ 或 合成 DID (Arkhangelsky et al. 2021)
│
└── 否 → 处理变量是否为连续型?
├── 是 → 断点回归 (RDD)
│ ├── 精确 RDD
│ └── 模糊 RDD (含 IV)
│
└── 否 → 工具变量法
├── 弱 IV 检验: Kleibergen-Paap rk F statistic
└── 面板 GMM: Arellano-Bond / Blundell-Bond适用条件:
核心假设:
标准 DID 模型: $$Y_{it} = \alpha + \beta \cdot D_{it} + \gamma \cdot X_{it} + \mu_i + \lambda_t + \varepsilon_{it}$$
其中 $D_{it} = Treatment_i \times Post_t$ 是核心 DID 项。$\beta$ 是平均处理效应 (ATT)。
交错 DID(多个政策时点):
| 方法 | 论文 | 适用场景 |
|---|---|---|
| Callaway-SantAnna | QJE 2021 | 组-时间 ATT,可处理不同处理强度 |
| Sun-Abraham | REStud 2021 | 交互加权估计 |
| Borusyak-Jaravel-Spinks | REStud 2024 | 反事实推断,效率更高 |
| Goodman-Bacon | QJE 2021 | 分解诊断工具 |
适用条件:
Arkhangelsky et al. 2021 (Synthetic DID): 结合 SCM 和 DID,适用于:
精确 RDD: $$Y_i = \alpha + \beta \cdot D_i + f(X_i) + \varepsilon_i$$ $D_i = 1(X_i \geq c)$,$f(\cdot)$ 是跑分变量的多项式函数。
模糊 RDD: 断点仅影响处理概率,估算 LATE(局部平均处理效应)。
核心检验:
工具变量质量评估:
| 标准 | 要求 | 评估方法 |
|---|---|---|
| 相关性 | F统计量 > 10 | 第一阶段 F 统计量 |
| 排他性 | Z 不影响 Y(除通过 X 外) | 理论论证 |
| 外生性 | Z 不受 Y 影响 | 理论论证 |
| 唯一性 | Z 仅通过 X 影响 Y | 理论论证 |
估计方法:
固定效应模型: $$Y_{it} = \alpha + \beta \cdot X_{it} + \mu_i + \lambda_t + \varepsilon_{it}$$
动态面板 GMM: $$Y_{it} = \alpha + \rho \cdot Y_{i,t-1} + \beta \cdot X_{it} + \mu_i + \varepsilon_{it}$$
## 处理组定义
| 标准 | 具体定义 | 数据来源 |
|------|----------|----------|
| 行业标准 | 属于 [具体行业代码] | CSMAR / Wind |
| 规模标准 | 总资产 > [阈值] 亿元 | CSMAR / Wind |
| 所有制标准 | 国有企业 / 民营企业 | CSMAR |
| 地区标准 | 位于 [省份/城市] | CSMAR |
## 对照组定义
对照组选择原则:
1. **行业匹配**:与处理组同行业
2. **规模相近**:与处理组规模相近(±20%)
3. **时间匹配**:同期上市
4. **排除标准**:剔除金融公司、ST公司、退市公司## 时间窗口
| 阶段 | 时间范围 | 说明 |
|------|----------|------|
| 政策前期 | [YYYY-Q1] - [YYYY-Q4] | 平行趋势检验 |
| 政策当期 | [YYYY-Q1] | 政策实施时点 |
| 政策后期 | [YYYY-Q1] - [YYYY-Q4] | 长期效应分析 |
最小时间窗口:政策前后各 3 年
推荐时间窗口:政策前后各 5 年生成 VARIABLE_DEFINITIONS.md:
# 变量定义表
## 被解释变量(Y)
| 变量名 | 中文名 | 定义 | 计算方式 | 数据来源 | 频率 | 预期符号 |
|--------|--------|------|----------|----------|------|----------|
| y_main | [主变量] | [经济学定义] | [计算公式] | [来源] | Annual | +/- |
| y_robust1 | [稳健性变量1] | ... | ... | ... | ... | +/- |
| y_robust2 | [稳健性变量2] | ... | ... | ... | ... | +/- |
## 核心解释变量(X)
| 变量名 | 中文名 | 定义 | 计算方式 | 数据来源 | 频率 | 预期方向 |
|--------|--------|------|----------|----------|------|----------|
| treat | 处理变量 | Treatment×Post | 虚拟变量 | 政策数据库 | - | + |
| treat_intensity | 处理强度 | [定义] | [计算] | 政策数据库 | Annual | + |
| x_main | [核心变量] | [定义] | [计算] | [来源] | ... | +/- |
## 控制变量
### 公司层面
| 变量名 | 中文名 | 定义 | 计算方式 | 数据来源 | 理由 |
|--------|--------|------|----------|----------|------|
| Size | 企业规模 | Ln(总资产) | Ln(总资产) | CSMAR/Wind | 规模效应 |
| Lev | 资产负债率 | 总负债/总资产 | 财务比率 | CSMAR/Wind | 资本结构 |
| ROA | 资产收益率 | 净利润/总资产 | 财务比率 | CSMAR/Wind | 盈利能力 |
| MB | 市值账面比 | 市值/账面价值 | 市场/账面 | CSMAR | 成长性 |
| Age | 企业年龄 | Ln(上市年限+1) | 年份计算 | CSMAR | 生命周期 |
| TOP1 | 股权集中度 | 第一大股东持股比例 | 持股比例 | CSMAR | 公司治理 |
| Dual | 两职合一 | 董事长兼总经理 | 虚拟变量 | CSMAR | 公司治理 |
| Board | 董事会规模 | 董事人数 | 人数 | CSMAR | 公司治理 |
| SOE | 所有制 | 国有企业 | 虚拟变量 | CSMAR | 所有制效应 |
### 宏观层面
| 变量名 | 中文名 | 定义 | 计算方式 | 数据来源 |
|--------|--------|------|----------|----------|
| GDP_g | GDP增速 | GDP同比增长率 | 同比 | 国家统计局 |
| M2_g | M2增速 | M2同比增长率 | 同比 | 央行 |
| CPI | 通胀率 | 消费者价格指数 | 同比 | 国家统计局 |
| HHI | 行业集中度 | Herfindahl 指数 | 计算 | CSMAR |
## 固定效应设置
| 固定效应 | 目的 | 是否加入 |
|----------|------|----------|
| 公司固定效应 (μᵢ) | 控制不随时间变化的个体异质性 | ✅ 必须 |
| 年度固定效应 (λₜ) | 控制共同时间趋势 | ✅ 必须 |
| 行业×年度 | 控制行业共同冲击 | ✅ 推荐 |
| 省份×年度 | 控制地区共同冲击 | ✅ 推荐 |
| 公司×行业趋势 | 控制公司特定趋势 | ⚠️ 可选 |
## 标准误聚类
| 聚类维度 | 理由 | 适用场景 |
|----------|------|----------|
| 公司层面 | 公司内观测相关 | 默认选项 |
| 公司×年度双维 | 既有个体内相关又有年间相关 | 标准做法 (CGM 2011) |
| 行业×年度 | 行业层面冲击相关 | 有明显行业效应时 |
| 省份×年度 | 省份层面冲击相关 | 地区政策研究 |
## 变量符号约定
```python
# Stata 变量命名规范
y_main = "innovation" # 被解释变量
treat = "did" # DID 交互项
x_vars = ["size", "lev", "roa", "mb", "age", "top1", "dual", "board", "soe"]
macro_vars = ["gdp_g", "m2_g", "cpi"]
fe = "i.stock_code i.year" # 固定效应
cluster = "stock_code" # 聚类维度
---
# 阶段4:识别策略详细设计
## 4.1 DID 详细设计
### 平行趋势假设
**事件研究设计**(必须做):
$$Y_{it} = \alpha + \sum_{k=-T}^{-2} \delta_k D_{it}^k + \sum_{k=0}^{K} \gamma_k D_{it}^k + \gamma \cdot X_{it} + \mu_i + \lambda_t + \varepsilon_{it}$$
其中 $D_{it}^k = Treatment_i \times 1(t = T_0 + k)$。
**平行趋势检验要点**:
- 政策前各期 ($k < 0$) 的系数 $\delta_k$ 应统计上不显著(置信区间包含0)
- 绘制 $\delta_k$ 的系数图(95%置信区间)
- 可使用 `modern_did.py` 的 `event_study_data()` 方法
### 交错 DID 特别注意事项
当存在多个处理时点时:
| 问题 | 解决方案 |
|------|----------|
| 不同处理时点导致处理状态定义不一致 | 使用 Callaway-SantAnna 组-时间 ATT |
| 早期处理组作为晚期处理组对照组 | Borusyak-Jaravel-Spinks 反事实推断 |
| 存在处理效应异质性 | Sun-Abraham 交互加权估计 |
| 处理效应随时间变化 | 事件研究 + 动态效应分解 |
### ModernDiDEngine 使用
```python
from modern_did import ModernDiDEngine
# 初始化
engine = ModernDiDEngine(
df=data,
y_var="innovation", # 被解释变量
treat_var="treatment", # 处理组虚拟变量
time_var="year", # 时间变量
unit_var="stock_code", # 单位变量
x_vars=["size", "lev", "roa", "mb", "age", "top1"],
cluster_var="stock_code" # 聚类变量
)
# 1. Callaway-SantAnna (推荐)
result_cs = engine.cs()
print(f"CS ATT: {result_cs.coef:.4f} (SE: {result_cs.se:.4f})")
# 2. Borusyak-Jaravel-Spinks
result_bjs = engine.bjs()
print(f"BJS ATT: {result_bjs.coef:.4f} (SE: {result_bjs.se:.4f})")
# 3. Sun-Abraham
result_sa = engine.sa()
print(f"SA ATT: {result_sa.coef:.4f} (SE: {result_sa.se:.4f})")
# 4. Goodman-Bacon 分解(诊断工具)
bacon_df = engine.bacon()
print(bacon_df)
# 5. 事件研究数据
event_study = engine.event_study_data(horizons=range(-5, 6))
engine.plot_event_study(estimator="cs", horizons=range(-5, 6), save_path="event_study.pdf")
# 6. Honest DiD (Rambachan-Roth 敏感性分析)
honest_result = engine.honest_did(m=0.5, delta_grid=None)
print(honest_result)
# 7. Wild Bootstrap
wild_result = engine.wild_bootstrap(n_boot=999, cluster_var="stock_code")
print(f"Wild Bootstrap ATT: {wild_result.coef:.4f} (p={wild_result.pval:.4f})")from rdd import RDDEngine
# 初始化
rdd = RDDEngine(
df=data,
outcome="performance", # 结果变量
running="score", # 跑分变量
cutoff=0, # 断点位置
treatment="treated" # 处理变量
)
# 1. 带宽选择
bw_ik = rdd.bandwidth_ik() # Imbens-Kalyanaraman 2012
bw_cct = rdd.bandwidth_cct() # Calonico-Cattaneo-Titiunik 2014
# 2. 精确 RDD
sharp_result = rdd.sharp_rdd(bandwidth=bw_ik, kernel="triangular")
# 3. 模糊 RDD(需要工具变量)
fuzzy_result = rdd.fuzzy_rdd(instrument="fuzzy_inst", bandwidth=bw_ik)
# 4. McCrary 密度检验
mccrary = rdd.mccrary_test()
print(f"McCrary t-stat: {mccrary['t_stat']:.3f}, p-value: {mccrary['p_value']:.3f}")
# 5. 预先指定变量连续性检验
covariates = ["size", "lev", "age"]
for var in covariates:
continuity_test = rdd.test_covariate_balance(var)
print(f"{var}: p-value = {continuity_test['p_value']:.3f}")from iv_panel import IVPanel
# 初始化
iv = IVPanel(
df=data,
y_var="innovation", # 被解释变量
instruments=["iv1", "iv2"], # 工具变量列表
x_vars=["size", "lev", "roa"] # 外生控制变量
)
# 1. 第一阶段
first_stage = iv.first_stage()
print(f"First Stage F: {first_stage['f_stat']:.2f}")
# 2. 第二阶段
second_stage = iv.second_stage()
print(f"2SLS Coefficient: {second_stage['coef']:.4f}")
# 3. 弱工具变量检验
kp_f = iv.weak_instrument_test()
print(f"Kleibergen-Paap rk F: {kp_f:.2f}") # > 10 表示非弱 IV
# 4. 过度识别检验(Sargan-Hansen)
overid = iv.overidentification_test()
# 5. 面板 GMM
gmm_result = iv.panel_gmm()from synthetic_control import SyntheticControl
# 初始化
sc = SyntheticControl(
df=data,
treated_unit="treated_id",
outcome_var="y",
control_pool=["ctrl1", "ctrl2", "ctrl3", ...],
time_var="year",
treatment_time=2015
)
# 1. 合成控制
result = sc.fit()
# 2. 推断(置换检验)
placebo_results = sc.placebo_test(n_permutations=500)
# 3. 绘图
sc.plot(save_path="sc_results.pdf")
# 4. RMSPE 比率
rmspe_ratio = sc.rmspe_ratio()
# 合成 DID(Arkhangelsky et al. 2021)
from synthetic_did import SyntheticDID
sdid = SyntheticDID(
df=data,
treated_unit="treated_id",
outcome_var="y",
time_var="year",
treatment_time=2015,
control_pool=[...]
)
sdid_result = sdid.fit()生成 ROBUSTNESS_PLAN.md:
| 编号 | 检验名称 | 具体操作 | 预期结果 | 对应输出 |
|---|---|---|---|---|
| R1 | 平行趋势检验 | 事件研究设计,预处理系数不显著 | 预处理系数 CI 包含 0 | 图2 |
| R2 | 安慰剂检验 | 500次随机处理时点/处理组 | 伪系数分布在0附近 | 图6 |
| R3 | 替换被解释变量 | 使用替代指标度量 Y | 核心结论不变 | 表A3 |
| R4 | 替换核心解释变量 | 使用替代指标度量 X | 核心结论不变 | 表A4 |
| R5 | 子样本回归 | 去除金融/ST/极端值 | 核心结论不变 | 表A5-A8 |
| R6 | 双重差分估计量比较 | CS/BJS/SA/Gardner 对比 | 量级方向一致 | 表3 |
| 编号 | 检验名称 | 具体操作 | 对应输出 |
|---|---|---|---|
| R7 | Bacon 分解 | Goodman-Bacon QJE 2021 | 诊断表 |
| R8 | Honest DiD | Rambachan-Roth 2023 | 敏感性表 |
| R9 | Wild Bootstrap | Wu 1986 / Cameron et al. 2008 | p值 |
| R10 | PSM+DID | 倾向得分匹配后做 DID | 表A9 |
| R11 | 增加控制变量 | 加入行业×年度固定效应 | 表A10 |
| R12 | 不同标准误 | Robust vs 聚类 vs 双维聚类 | 表A11 |
| R13 | Oster 边界 | Oster 2019 δ 方法 | 敏感性分析 |
| R14 | 带宽敏感(RD) | IK / CCT / 0.5x / 2x 带宽 | 表A12 |
| R15 | 不同时间窗口 | 政策前后 3/5/7 年 | 表A13 |
from robustness_runner import RobustnessRunner
runner = RobustnessRunner()
# 运行所有稳健性检验
report = runner.run_all(df=data, main_result=main_result)
# 1. 平行趋势检验
pt_result = runner.parallel_trends(data, horizons=range(-5, 6))
# 2. 安慰剂检验(500次随机)
placebo = runner.run_placebo(data, n_permutations=500)
runner.plot_placebo_distribution(placebo, save_path="placebo.pdf")
# 3. 子样本检验
subsample_results = runner.run_subsample(data, subsample_defs=[
{"name": "exclude_finance", "filter": "industry != '金融'"},
{"name": "exclude_st", "filter": "st == 0"},
{"name": "high_tech", "filter": "industry in ['计算机', '电子']"}
])
# 4. Oster 边界
oster = runner.oster_bounds(
df=data,
y_var="innovation",
treat_var="did",
x_vars=["size", "lev", "roa", "mb", "age"]
)
# 5. Wild Bootstrap
wild = runner.wild_bootstrap(df=data, n_boot=999, cluster_var="stock_code")
# 生成报告
print(report.summary())生成 ENDOGENEITY_PLAN.md:
| 检验方法 | 原假设 | 检验统计量 | 阈值 | Python/Stata |
|---|---|---|---|---|
| Durbin-Wu-Hausman | X 是外生的 | F 统计量 | p < 0.1 表示内生 | estat endogenous |
| Sargan-Hansen | 工具变量过度识别 | J 统计量 | p > 0.1 表示工具有效 | estat overid |
| 弱工具变量 | 第一阶段 F < 10 | F 统计量 | F > 10 表示非弱 IV | ivweakparm |
[见阶段4.3]
$$Y_{it} = \alpha + \beta \cdot X_{i,t-1} + \gamma \cdot Controls_{it} + \mu_i + \lambda_t + \varepsilon_{it}$$
使用 X 的滞后项作为解释变量,缓解同期内生性。
from iv_panel import IVPanel
gmm = IVPanel(df=data, y_var="y", instruments=["l.x1", "l.x2"])
gmm_result = gmm.arellano_bond_gmm()from robustness_runner import RobustnessRunner
# 计算使核心系数归零所需的遗漏变量强度
oster_result = runner.oster_bounds(
df=data,
y_var="innovation",
treat_var="did",
x_vars=["size", "lev", "roa", "mb", "age"]
)
# 如果 δ > 1,说明需要比可观测变量更强的遗漏变量才能归零# 实证研究设计
## 1. 研究问题
[从 IDEA_REPORT.md 提取研究问题]
## 2. 识别策略
### 2.1 策略选择
- **选择策略**:[DID / IV / RDD / 面板 GMM / SCM]
- **选择理由**:[为什么这个策略最适合本研究]
### 2.2 策略适用性检验
- [列出关键假设和检验方法]
## 3. 样本构建
### 3.1 数据来源
- 公司财务数据:[CSMAR / Wind / Tushare]
- 宏观数据:[国家统计局 / 央行]
- 政策数据:[具体来源]
### 3.2 样本选择
- 时间范围:[YYYY - YYYY]
- 处理组:[N 家]
- 对照组:[N 家]
- 总观测值:[N]
### 3.3 排除标准
- 金融公司
- ST/*ST 公司
- 上市不满 [X] 年
- 关键变量缺失
## 4. 变量定义
[见 VARIABLE_DEFINITIONS.md]
## 5. 估计方法
### 5.1 基准模型
$$Y_{it} = \alpha + \beta \cdot D_{it} + \gamma \cdot X_{it} + \mu_i + \lambda_t + \varepsilon_{it}$$
### 5.2 固定效应设置
- 公司固定效应
- 年度固定效应
- [行业×年度 / 省份×年度]
### 5.3 标准误聚类
- [公司层面 / 公司×年度双维]
## 6. 稳健性检验
[见 ROBUSTNESS_PLAN.md]
## 7. 内生性处理
[见 ENDOGENEITY_PLAN.md]
## 8. 预期结果
- 核心系数方向:[正向 / 负向]
- 核心系数显著性:[1% / 5% / 10%]
- 经济显著性:[具体含义]# 实验执行计划
## 阶段1:数据准备(第1-2周)
- [ ] 获取公司财务数据
- [ ] 获取宏观数据
- [ ] 构建政策/处理变量
- [ ] 合并面板数据集
- [ ] 变量清洗和计算
- [ ] Winsorize 处理
## 阶段2:描述性统计(第2周)
- [ ] 全样本描述性统计(表1)
- [ ] 处理组/对照组均值差异检验
- [ ] 相关性矩阵
- [ ] 样本筛选流程记录
## 阶段3:主回归(第3-4周)
- [ ] 基准回归
- [ ] 平行趋势检验
- [ ] 动态效应分析
- [ ] 异质性分析
## 阶段4:稳健性检验(第4-5周)
- [ ] R1-R6 必做检验
- [ ] R7-R15 扩展检验
## 阶段5:内生性处理(第5周)
- [ ] IV / GMM 估计
- [ ] 内生性检验
## 阶段6:论文写作(第6周)
- [ ] 实证结果表格整理
- [ ] 结果描述撰写© csmar432, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
Just SKILL.md in .agents/skills/fin-experiment-design of csmar432/finai-research.
Open the folder on GitHubat commit 47eebb7
Fin Experiment Design next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Fin Experiment Design this skillcsmar432/finai-research | 109 | — | ~4.2k | Automated safety check: Pass | MIT | |
| Causalai-analyst-lab/ai-analyst | 304 | — | ~1.8k | Automated safety check: Pass | MIT | |
| Judea PearlK-Dense-AI/mimeo | 282 | — | ~1.7k | Automated safety check: Pass | MIT | |
| Academic Paper Verifybrycewang-stanford/Auto-Empirical-Research-Skills | 4.6k | — | ~2.9k | Automated safety check: Pass | Custom licence | |
| Designing Experimentsforyourhealth111-pixel/Vibe-Skills | 3.6k | — | ~600 | Automated safety check: Pass | Apache-2.0 | |
| Jape Identification Strategyfranklee16/academic-research-skills | 223 | 1 repos | ~707 | Automated safety check: Pass | None |
ai-analyst-lab/ai-analyst
Causal inference toolkit for when experiments are not possible: estimate treatment effects from observational data with assumption checks and mandatory caveats.
K-Dense-AI/mimeo
Applies Judea Pearl's causal reasoning frameworks to distinguish correlation from causation, evaluate AI capabilities, and make counterfactual decisions.
brycewang-stanford/Auto-Empirical-Research-Skills
Thoroughly verify all code, tables, figures, modeling decisions, and quantitative claims in an academic paper against its source R scripts and output files.
foryourhealth111-pixel/Vibe-Skills
Design experiments and quasi-experiments before analysis. An agent skill from foryourhealth111-pixel/Vibe-Skills.
franklee16/academic-research-skills
A skill your agent uses when designing or defending the empirical identification of a Journal of Applied Econometrics (JAE) manuscript — a credible strategy applied to real data, with assumptions…
foryourhealth111-pixel/Vibe-Skills
Estimate causal effects from existing data. An agent skill from foryourhealth111-pixel/Vibe-Skills.
csmar432/finai-research
生成研究/项目架构图、流程图、层次图(swimlane / processflow / hierarchytree)。适合 PPT 汇报、技术文档、综述插图。输出风格接近 draw.io,可选 graphviz(高质量)/ matplotlib(零依赖)双后端。
csmar432/finai-research
根据用户输入或已有研究输出(文献综述/想法报告/新颖性报告),自动生成或更新FINBRIEF.md,减少用户填写负担. An agent skill from csmar432/finai-research.
csmar432/finai-research
根据REFINEDDESIGN.md中的变量定义,自动获取所需数据并生成可执行的回归分析脚本(Python/Stata)。
csmar432/finai-research
针对经济金融研究方向的创意生成与评估。生成8-12个可发表的研究idea,过滤后在数据可行的情况下进行小规模实证验证,输出排序后的研究想法报告。
csmar432/finai-research
经济金融研究的完整想法发现流程。从研究方向出发,经过文献综述、想法生成、新颖性验证、实证方法设计和数据获取,输出经过数据实证验证的可执行研究方案。
csmar432/finai-research
经济金融领域的系统性文献综述。整合 Semantic Scholar + ArXiv + OpenAlex + NBER 构建引文网络,识别研究缺口,生成结构化文献地图。
Categories
经济金融实证方法设计。根据研究想法和REFINEDDESIGN.md,生成完整的实证研究设计方案,覆盖识别策略选择、样本构建、变量定义、稳健性检验清单和内生性处理方案。. Fin Experiment Design is an agent skill from csmar432/finai-research.
Fin Experiment Design fits situations like: tasks that involve Experimental design; tasks that involve Design tokens; tasks that involve Econometrics and empirical research.
Run `npx skills add csmar432/finai-research --skill fin-experiment-design -a claude-code`. Or copy the skill folder (.agents/skills/fin-experiment-design in csmar432/finai-research) into .claude/skills/fin-experiment-design in your project. Claude Code loads it when a task matches its description.
Run `npx skills add csmar432/finai-research --skill fin-experiment-design -a codex`. Or copy the skill folder (.agents/skills/fin-experiment-design in csmar432/finai-research) into .agents/skills/fin-experiment-design in your project. Codex loads it when a task matches its description.
Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add csmar432/finai-research --skill fin-experiment-design -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/fin-experiment-design, .gemini/skills/fin-experiment-design, .github/skills/fin-experiment-design and .opencode/skills/fin-experiment-design in your project.
Going by SKILL.md and its folder, Fin Experiment Design needs the command-line tools its instructions call (python). Our summary lists: Python 3.
SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.
Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.
Fin Experiment Design is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.
About 4.2k tokens (SKILL.md is roughly 17k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.
Skills that share tags, products or a category with Fin Experiment Design: Causal (ai-analyst-lab/ai-analyst, 304 stars), Judea Pearl (K-Dense-AI/mimeo, 282 stars), Academic Paper Verify (brycewang-stanford/Auto-Empirical-Research-Skills, 4.6k stars) and Designing Experiments (foryourhealth111-pixel/Vibe-Skills, 3.6k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
csmar432 (a GitHub user) maintains it in csmar432/finai-research, which has 109 GitHub stars. The repository holds 15 skills in this directory. The repository was last updated on October 6, 2026.
Source: csmar432/finai-research on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.