Skip to content

📖 《把 AI 当助手——经济实证研究的诚信、方法与工具》双语网页版:每章中文部在前,English Edition 在后,内容与最新合订 PDF 一致。

第9章 · 推断统计与实证策略 ​


本章导览 ​

学习目标 ​

完成本章后,你应当能够:

  1. 说出 GLM(一般线性模型)如何统摄 t 检验、方差分析与回归——三者不是“三种方法”,而是同一枚硬币的不同面

  2. 选择 为自己的研究假说匹配最合适的识别策略(OLS / FE / IV / DID / PSM / RDD)

  3. 完成 用 stata-mcp 驱动的“六步法”实证全流程(描述 → 基准 → 内生性 → 稳健性 → 机制 → 异质性)

  4. 解释 每种识别策略“解决了第 4 章七大效度威胁中的哪一条”

  5. 独立撰写 一份可复现的实证分析 do 文件(从 use data/raw/ 到 esttab using ...)

核心理念 ​

这句话是整章的灵魂。你在第 8 章已经学会给数据做“体检”(描述统计),本章要做的是:先基于理论把模型设定好,再用数据去验证它。如果你反复换变量、换样本直到 p < 0.05——那叫 p-hacking,是本章诚信检查点 S9.1 的红线。

节结构 ​

表 9.1 节结构。

L3|L3|L3

节 & 标题 & 核心方法
9.0 & GLM 统摄视角 & t 检验/ANOVA/回归同属 GLM;双组比较;2×2 因子设计
9.1 & OLS 基准回归 & reg / vce(robust) / vif / estat hettest / estat ovtest
9.2 & 面板数据:FE 与 RE & xtset / reghdfe / hausman / BP-LM
9.3 & 工具变量法(IV/2SLS) & ivregress 2sls / estat firststage / 排他性
9.4 & 双重差分法(DID) & did_multiplegt / eventstudyinteract / 平行趋势
9.5 & PSM 与 RDD & psmatch2 / teffects psmatch / rdrobust
9.6 & 稳健性与异质性 & 替换变量 / 子样本 / 规格曲线
9.7 & 中介效应与机制检验 & sgmediation(Sobel + Bootstrap)
9.8 & ABM 仿真实验(选修) & ODD 协议 / 四川水稻保险 ABM
合计 & &\


[提示] 本章在全手册的位置

  • 承接第 8 章:第 8 章教你“数据体检做扎实,回归才跑得放心”——描述统计、缺失值处理、缩尾、变量转换。本章直接在这些“干净数据”上建模。

  • 回指第 4 章:每个识别策略(IV / DID / PSM / RDD / FE)都对应解决第 4 章七大效度威胁中的一条或多条。写论文时,你必须说清楚“我用 DID 是因为要解决选择偏差+历史效应”。

  • 对比第 10 章:本章走的是“回归路线”(What 型问题:X 对 Y 有没有因果效应?有多大?);第 10 章走的是“案例路线”(How 型问题:这个过程是怎样发生的?)。两条路线在第 4 章 §4.5“研究策略三分选型”已做铺垫。

  • 主例数据集:bank_panel.dta(100 家上市银行 × 5 年面板),变量包括 roe(因变量)、size、leverage、governance、board_size、bank_id、year。三方向副例:【金】资本结构决定因素 /【险】农业保险需求决定因素 /【农】微型金融贷款可得性。

§9.0 GLM 统摄视角 ​

📐 结构图示(书版示意图的文字要点)

  1. tikzpicture
  2. ->,thick,NavyBlue
  3. t 检验
  4. 例:
  5. ANOVA
  6. OLS 回归
  7. MSB
  8. MSW

图 9.1 GLM 统摄视角——t 检验 / ANOVA / 回归不是三种方法,而是同一棵树上按 X 类型剪出的三根枝。


9.0.1 GLM 家族:t 检验 / ANOVA / 回归同源 ​

GLM 的一般形式 y=β0+β1x1+⋯+βnxn+ε,其中 xi 可以是连续变量或 0/1 虚拟变量。按 xi 类型分流:

表 9.2 GLM 家族:t 检验 / ANOVA / 回归同源。

L3|L3|L3

预测变量类型 & 对应方法 & 等价说法
一个虚拟变量(比较两组) & 方差分析(ANOVA) = t 检验 & reg y i.group 中 group 系数的 t 检验
虚拟变量 + 协变量 & 协方差分析(ANCOVA) & 加了控制变量的 ANOVA
多个连续预测变量 & 多元回归 & 你熟悉的 OLS
多个结果变量 & 多变量回归 / MANOVA & 方程组
一个方程的因变量是另一个方程的自变量 & 结构方程模型(SEM) & 路径分析\

一句话总结:GLM 是一个"超级框架",t 检验和 ANOVA 只是它在特定变量类型下的"别名"。


9.0.2 双组比较 = 最简单的回归 ​

关键等式:当预测变量是 0/1 虚拟变量时,reg y i.group 的 β1 恰好等于独立样本 t 检验的两组均值差,回归的 t 统计量恰好等于独立样本 t 检验的 t 值。完整推导见 §9.1 OLS 基准回归(含协变量扩展)。


9.0.3 2×2 因子设计与交互项 ​

双因素 GLM:y=β0+β1x1+β2x2+β3x1x2+ε,β3 是交互效应。核心警示:当 β3 显著时,β1 和 β2 不能单独解读——这正是 §9.4 DID 估计量 β3(Treati×Postt) 的底层逻辑。完整 DID 推导见 §9.4。


9.0.4 模型设定的理论优先原则 ​

“模型设定应该基于对所研究的现象的理论思考,而不是什么模型能够最好地拟合观测数据。数据是用来验证模型的,而不是用来设定模型的。”——这正是本章诚信检查点 S9.1 不 p-hacking 的根本依据。

表 9.3 模型设定的理论优先原则。

L2|L2

理论优先(正确做法) & 数据驱动(红线行为)
先根据文献和理论确定因变量、核心自变量、控制变量 & 先把所有变量扔进去,看哪个显著留哪个
先确定样本范围(如"沪深 A 股上市银行 2019–2023") & 事后剔除"异常值"直到结果显著
先确定一个主模型,再做稳健性检验 & 跑了 20 个设定只报告显著的那一个
用规格曲线展示所有合理设定下的结果分布 & 隐瞒不显著的设定\

操作建议:动手跑回归之前,先在文件开头用注释写清楚你的理论模型:

* ==========================================================
* 理论模型(写代码前先确定,不得事后修改)
* ==========================================================
* 假说 H1:公司治理水平(governance)正向影响银行 ROE
* 因变量:roe
* 核心自变量:governance
* 控制变量:size(规模)、leverage(杠杆)、board_size(董事会规模)
* 理论依据:代理理论(Jensen & Meckling, 1976)
* 样本范围:沪深 A 股上市银行 2019-2023(100家×5年=500 obs)
* 识别策略:OLS 基准 + FE 稳健性(解决不随时间变的遗漏变量)
* ==========================================================

9.0.5 Stata 演示:t 检验 / ANOVA / 回归的等价性 ​

下面用主例数据 bank_panel.dta 演示三种命令如何得到相同的结论:

* -- 加载数据 --
use data/clean/bank_panel.dta, clear

* 生成一个二值分组变量:governance 高于中位数为"高治理组"
qui sum governance, detail
gen hi_gov = (governance > r(p50))
label var hi_gov "高治理组(1) vs 低治理组(0)"

* 方法一:独立样本 t 检验
ttest roe, by(hi_gov)

* 方法二:单因素方差分析(ANOVA)
anova roe i.hi_gov

* 方法三:OLS 回归(与 t 检验等价)
reg roe i.hi_gov

* 进阶:2×2 因子设计(等价于 DID 的结构)
gen post = (year >= 2021)
reg roe i.hi_gov##i.post   % 1.hi_gov#1.post 即 DID 估计量

等价性验证清单:

表 9.4 Stata 演示:t 检验 / ANOVA / 回归的等价性。

L4|L4|L4|L4

比较维度 & ttest & anova & reg y i.group
效应规模 & 均值差 diff & — & β1 系数
检验统计量 & t & F = t² & t
p 值 & ✅(相同) & ✅(相同) & ✅(相同)
置信区间 & ✅ & — & ✅
可扩展性 & 只能两组 & 可多组 & 可加控制变量/交互项\

结论:学会了 reg 就掌握了 t 检验和 ANOVA。GLM 框架让你用一套命令应对从简单比较到复杂因果推断的所有场景。


9.0.6 三方向副例中的 GLM 思维 ​

表 9.5 三方向副例中的 GLM 思维。

L4|L4|L4|L4

方向 & 研究问题 & GLM 设定 & 交互项含义
【金】资本结构 & 公司治理是否影响杠杆率? & reg leverage i.hi_gov size roe & 治理×规模:大公司的治理效应是否不同?
【险】农保需求 & 风险厌恶是否影响投保决策? & logit insure i.risk_averse income age & 风险厌恶×收入:高收入农户的风险厌恶效应更强?
【农】微型金融 & 联保机制是否提高还款率? & & 联保×农村:联保在农村地区效果更突出?\

[重点] 记住:无论你的方向是金融、保险还是农村经济,底层的统计逻辑都是 GLM。差异只在于因变量类型(连续 → OLS;二值 → Logit/Probit)、数据结构(截面/面板/时间序列)和识别策略(§9.1–§9.5)。

方法选型决策树(速查) ​

决策树原文 ​

你的研究问题是因果推断吗?
+-- 否 -> 描述统计/相关分析(第 8 章)
+-- 是 -> 你有随机分组(实验)吗?
    +-- 是 -> 真实验分析(t检验/ANOVA -> §9.0 GLM)
    +-- 否 -> 观测数据(非实验/事后追溯)
        +-- 有外生冲击/政策变化?
        |   +-- 是 + 冲击前后两期 -> DID(§9.4)
        |   +-- 是 + 连续处理变量 -> RDD(§9.5)
        +-- 有合适的工具变量?
        |   +-- 是 -> IV/2SLS(§9.3)
        |   +-- 否 -> 有匹配对照组?
        |       +-- 是 -> PSM(§9.5)
        |       +-- 否 -> 面板数据?
        |           +-- 是 -> FE/RE(§9.2)
        |           +-- 否 -> OLS + 充分控制变量(§9.1)
        +-- 以上均不满足 -> 诚实地说"相关但无法确定因果"

如何使用这棵决策树 ​

决策树的使用分三步:

第一步:确认你的研究问题类型。 如果你问的是“X 和 Y 有没有关系”(相关),第 8 章描述统计就够了。如果你问的是“X 是否导致了 Y”(因果),才需要往下走。

第二步:盘点你手里的“识别资源”。 依次检查:有没有外生政策冲击?有没有可用的工具变量?有没有可匹配的对照组?数据是面板还是截面?——你在第 5 章下载数据、第 6 章设计问卷时,就应该开始思考这些问题。

第三步:选择最“干净”的策略。 优先选择识别假设最少的策略(DID 需要平行趋势;IV 需要排他性;PSM 需要可观测对照;FE 只需要“遗漏变量不随时间变”)。如果一个策略的假设在你的场景中不成立,退而求其次选下一个——但必须在论文中诚实讨论局限。


三层结构说明 ​

+------------------------------------------------------+
|  第一层:数据结构决定方法边界                          |
|                                                      |
|  截面数据 --> OLS / PSM / RDD / IV                    |
|  面板数据 --> FE / RE / DID / IV                      |
|  时间序列 --> ARIMA / VAR(本手册不展开,见附录 B)     |
|                                                      |
+------------------------------------------------------+
|                                                      |
|  第二层:研究问题决定识别策略                          |
|                                                      |
|  "X 和 Y 有没有关系" --> OLS / FE                     |
|  "X 是否导致 Y"     --> 需要因果识别策略              |
|    - 有外生政策冲击? --> DID                          |
|    - 有工具变量?     --> IV/2SLS                      |
|    - 有断点/门槛?   --> RDD                          |
|    - 选择偏差来自可观测变量? --> PSM                  |
|                                                      |
+------------------------------------------------------+
|  第三层:诊断与修正                                   |
|                                                      |
|  异方差   --> 稳健标准误(vce(robust))               |
|  共线性   --> 删变量 / 合并变量                       |
|  设定误差 --> 加高次项 / 交互项                       |
|  内生性   --> IV / FE / DID                          |
|                                                      |
+------------------------------------------------------+
|                                                      |
|  [提示] 机制分析的前提:主效应已经显著且稳健               |
+------------------------------------------------------+

§9.1 OLS 基准回归(上):假设与诊断 ​

核心理念:OLS 不只是一个命令,它是一套“契约”——你假设数据满足五个条件,Stata 才能保证系数无偏且有效。先诊断,后信任。

9.1.1 OLS 五大经典假设(Gauss-Markov 条件) ​

在第 1 章你已经跑通了 reg roe size leverage governance board_size,但当时我们只关心“流程能走通”。现在正式问一个问题:凭什么相信这组系数?

答案是:凭五个假设全部成立。

表 9.6 OLS 五大经典假设(Gauss-Markov 条件)。

L5|L5|L5|L5|L5

编号 & 假设名称 & 数学表达 & 直觉含义 & 违反后果
A1 & 线性于参数 & y=β0+β1x1+⋯+βkxk+ε & 模型对 β 是线性的(x 可以非线性变换) & 系数含义错误
A2 & 随机抽样 & 样本从总体中 i.i.d. 抽取 & 每个观测相互独立、来自同一分布 & 标准误失效、推断不可靠
A3 & 无完全多重共线性 & 解释变量之间不存在精确线性关系 & 不能有某个 x 是其他 x 的完美线性组合 & Stata 自动 drop 变量
A4 & 零条件均值 & E(ε∣x1,…,xk)=0 & 误差项与解释变量不相关(无内生性) & 系数有偏且不一致(最严重)
A5 & 同方差 & Var(ε∣x)=σ2(常数) & 不管 x 取什么值,扰动项的波动幅度相同 & 系数仍无偏,但标准误有偏 → 推断失效\

[提示] 关键原则——“数据是用来验证模型的,而不是用来设定模型的”。五大假设是你“设定模型”时的理论承诺;诊断检验是你“验证承诺”的数据面证据。

A4 为什么最严重?因为一旦 E(ε∣x)≠0(遗漏变量、反向因果、测量误差),OLS 系数不仅这次错,样本再大也救不回来——这就是“不一致”的含义。第 9.3 节 IV 和第 9.2 节 FE 正是针对 A4 违反的两把手术刀。

9.1.2 异方差诊断 ​

异方差(Heteroskedasticity)= A5 被违反。直觉上,大银行的 ROE 波动可能比小银行大——这就造成了“不同 x 值对应不同方差”。

* -- 异方差诊断 --
* 前提:刚跑完 reg(诊断命令必须在 reg 之后立即使用)
use "data/clean/bank_panel.dta", clear
reg roe size leverage governance board_size

* 方法 1:Breusch-Pagan 检验(BP 检验)
* 原假设 H0:同方差(残差方差与解释变量无关)
estat hettest
* 输出示例:
*   chi2(4) = 15.23
*   Prob > chi2 = 0.0043
* 判断:p = 0.0043 < 0.05 -> 拒绝 H0 -> 存在异方差

* 方法 2:White 检验(更一般,允许交叉项)
estat imtest, white
* 输出示例:
*                  |       chi2     df      Pr > chi2
*   --------------+-----------------------------------
*   Fit |           23.45     14       0.0498
*   Squares |       18.67     14       0.1735
*   Skewness |       2.34      4       0.6734
*   Kurtosis |       3.12      4       0.5378
* 判断:Fit 行 p = 0.0498 < 0.05 -> 存在异方差证据

* -- 修正:使用稳健标准误重新回归 --
reg roe size leverage governance board_size, vce(robust)
* vce(robust) = Huber-White 稳健标准误
* 系数不变,标准误修正 -> t 值和 p 值可能变化

判断标准:

表 9.7 异方差诊断。

L3|L3|L3

检验结果 & 结论 & 下一步
BP 和 White 均 p > 0.10 & 未发现异方差证据 & 报告经典标准误即可
任一 p < 0.05 & 存在异方差 & 必须用 vce(robust) 重跑(详见 §9.1 下半)
0.05 < p < 0.10 & 边界情况 & 建议保守处理:用稳健标准误并在脚注说明\

9.1.3 多重共线性诊断 ​

多重共线性 = 解释变量之间高度相关(如 size 和 leverage 在大银行中往往同方向变化)。它不导致系数有偏,但让标准误膨胀 → 显著性下降 → “明明该显著的变量变得不显著”。

* -- 多重共线性诊断 --
* 必须在 reg 之后使用
estat vif
* 输出解读:
*   Variable |      VIF        1/VIF
*   ---------+----------------------
*   size     |     X.XX        0.XXXX
*   leverage |     X.XX        0.XXXX
*   ...
*   Mean VIF |     X.XX
*
* 判读规则(经验法则):
*   VIF > 10  -> 该变量存在严重共线性,需警惕
*   VIF > 5   -> 中度共线性,关注但不必恐慌
*   VIF < 5   -> 安全
*   Mean VIF > 3 -> 模型整体共线性偏高

* -- 简单相关矩阵辅助判断 --
correlate size leverage governance board_size
* 任何两个变量 |r| > 0.8 时,对应的 VIF 通常会 > 5

处理策略(按优先级排列):

  1. 不处理:如果核心变量系数方向和显著性未变,共线性只是让“锦上添花”的控制变量不显著——如实报告即可

  2. 减少冗余变量:去掉 VIF 最高且理论上最不必要的变量

  3. 合并变量:如多个指标衡量同一构念,用因子得分或均值合成(回指第 5 章 §5.4)

  4. 增大样本:共线性是“信息不足”的表现,更多数据有助于区分

9.1.4 模型设定误差(RESET 检验) ​

RESET 检验(Regression Equation Specification Error Test)回答一个根本问题:你的线性模型设定对吗?是否遗漏了重要的非线性项或交互项?

* -- RESET 检验(Ramsey 1969)--
estat ovtest
* 原假设 H0:模型设定正确(无遗漏的高次项)
* 备择 H1:模型存在设定误差
*
* 输出解读:
*   F(3, 495) = X.XX
*   Prob > F =    0.XXXX
* 判断:
*   p < 0.05 -> 拒绝 H0 -> 模型存在设定误差
*   p > 0.10 -> 不能拒绝 H0 -> 模型设定可接受

* -- 修正策略(按 RESET 显著时选用)--
* 策略 1:加入关键变量的平方项
gen size_sq = size^2
reg roe size size_sq leverage governance board_size
estat ovtest   /* 再检验:p 值是否改善? */

* 策略 2:加入可能的交互项(理论驱动)
gen gov_x_lev = governance * leverage
reg roe size leverage governance board_size gov_x_lev
estat ovtest   /* 再检验 */

* 策略 3:对因变量取对数(如果经济含义允许)
gen ln_roe = ln(roe) if roe > 0
reg ln_roe size leverage governance board_size

9.1.5 四大诊断的完整工作流 ​

把上面三个诊断整合成一个标准流程——以后每次跑完基准回归都照着走一遍:

* ======================================================
* §9.1 完整诊断流程模板(基于 bank_panel.dta)
* ======================================================
use "data/clean/bank_panel.dta", clear

* Step 1:基准回归
reg roe size leverage governance board_size
estimates store m1_baseline

* Step 2:异方差诊断
estat hettest          /* BP 检验 */
estat imtest, white    /* White 检验 */
* -> 记录两个 p 值,判断是否存在异方差

* Step 3:多重共线性诊断
estat vif
* -> 记录 Mean VIF,判断是否 < 3(安全)

* Step 4:模型设定检验
estat ovtest           /* RESET 检验 */
* -> 记录 p 值,判断是否需要加高次项

* Step 5:修正——使用稳健标准误重新回归
reg roe size leverage governance board_size, vce(robust)
estimates store m2_robust

* Step 6:输出对照表
esttab m1_baseline m2_robust using "output/ch09_diagnostics.rtf", ///
    replace b(%9.3f) se(%9.3f) ///
    title("表:OLS基准回归诊断对照") ///
    mtitles("经典标准误" "稳健标准误") ///
    stats(N r2, labels("观测数" "R²"))

诊断结果速查表:

表 9.8 四大诊断的完整工作流。

L5|L5|L5|L5|L5

诊断命令 & 检验的假设 & 原假设 H0 & p < 0.05 意味着 & 修正方案
estat hettest & A5 同方差 & 残差方差恒定 & 存在异方差 & vce(robust)
estat imtest, white & A5 同方差 & 残差方差恒定 & 存在异方差 & vce(robust)
estat vif & A3 无共线性 & 变量间无线性相关 & VIF > 10 严重共线 & 删变量 / 合并
estat ovtest & A1 线性设定 & 模型设定正确 & 遗漏非线性 / 交互项 & 加高次项或交互项\

△  诚信提醒(S9.1 前置):诊断结果不好时,正确做法是修正模型或如实报告局限,绝不是“反复换变量组合直到诊断全过”。后者是 p-hacking 的变体。

§9.1 OLS 基准回归(下):六步法第 1-2 步 ​

核心理念:稳健标准误不是“锦上添花”,而是发表期刊的最低门槛。掌握六步法全景,才知道自己现在走到了哪一步。

9.1.6 稳健标准误:从”能用”到”能发表” ​

上一节诊断完异方差后,修正方案就是 vce(robust)。但你还需要知道:面板数据中,同一个银行不同年份的观测值不独立(组内自相关),此时需要更强力的修正——聚类稳健标准误。

* -- 三种标准误对比 --
use "data/clean/bank_panel.dta", clear

* 方案 A:经典标准误(假设 A5 同方差 + A2 独立)
reg roe size leverage governance board_size
* 输出中标注:(无特殊标注 = 经典标准误)

* 方案 B:异方差稳健标准误(Huber-White,放松 A5)
reg roe size leverage governance board_size, vce(robust)
* 输出中标注:(robust SE)

* 方案 C:聚类稳健标准误(放松 A5 + A2,面板数据推荐)
reg roe size leverage governance board_size, vce(cluster bank_id)
* 输出中标注:(cluster SE)
* 含义:允许同一家银行不同年份的残差相互相关

* -- 选择规则 --
* 1. 截面数据 + 不确定是否同方差 -> vce(robust) 总是安全的
* 2. 面板数据 -> vce(cluster 个体ID) 是最低要求
* 3. 聚类数 G < 50 -> 考虑 wild cluster bootstrap(进阶,暂不展开)

三种标准误的选择决策:

表 9.9 稳健标准误:从”能用”到”能发表”。

L4|L4|L4|L4

数据结构 & 推荐标准误 & Stata 语法 & 理由
截面(每观测独立) & 稳健 & vce(robust) & 防异方差
面板(同个体多期) & 聚类 & vce(cluster bank_id) & 组内残差自相关
面板 + 时间冲击相关 & 双向聚类 & reghdfe ..., vce(cluster bank_id year) & 个体+时间双重相关\

9.1.6 stata-mcp 六步法概览 ​

六步法是本手册实证分析的总纲——从描述到结论,每一步都有明确的 Stata 命令和产出物。第 9 章 §9.1—§9.7 恰好对应这六步:

+----------------------------------------------------------------+
|            stata-mcp 六步法(实证分析全流程)                    |
+----------------------------------------------------------------+
|                                                                |
|  Step 1 · 描述统计                                             |
|  -----------------                                             |
|  §8.2 数据体检 + §8.3-8.4 一元/双变量分析                      |
|  命令:summarize / tab / correlate / winsor2                    |
|  产出:Table 1-3(描述统计表)、Figure 1-3(分布图/相关矩阵)|
|                                                                |
|  Step 2 · 基准回归                                             |
|  -----------------                                             |
|  §9.1-9.2 OLS / 面板固定效应回归                               |
|  命令:reghdfe ... vce(cluster bank_id)                        |
|  产出:Table 4(基准回归表,含混合/FE/RE/双向FE四列)          |
|                                                                |
|  Step 3 · 诊断检验                                             |
|  -----------------                                             |
|  §9.2 回归后诊断:异方差、自相关、多重共线性                    |
|  命令:hettest / vif / estat bgodfrey / estat abar             |
|  产出:诊断结果记录在 log 文件中                               |
|                                                                |
|  Step 4 · 内生性处理                                           |
|  -----------------                                             |
|  §9.3 IV / §9.4 DID / §9.5 PSM-RDD                           |
|  命令:ivregress 2sls / didregress / psmatch2 / rdrobust       |
|  产出:Table 5(内生性处理结果表)                              |
|                                                                |
|  Step 5 · 稳健性检验                                           |
|  -----------------                                             |
|  §9.6 三组稳健性 + 规格曲线                                    |
|  命令:替换变量/换标准误/子样本回归                            |
|  产出:Table 6(稳健性检验表)+ Figure(规格曲线图)           |
|                                                                |
|  Step 6 · 异质性分析与机制检验                                 |
|  -----------------                                             |
|  §9.7 分组回归 + 中介效应                                      |
|  命令:分组 reghdfe + Baron-Kenny 三步法 / sgmediation         |
|  产出:Table 7(机制检验表)+ Table 8(异质性分组表)          |
|                                                                |
+----------------------------------------------------------------+
|  产出:Table 8(异质性分组表)                                  |
|                                                                |
+----------------------------------------------------------------+

[提示] AI 辅助提示:使用 stata-mcp 时,你可以把诊断输出贴给 AI 问“这组结果有哪些潜在问题”——这是 S9.4 允许的合法用途(AI 解释输出,不生成系数)。

9.1.7 三方向副例:OLS 基准回归在你方向的变体 ​

主例用的是银行 ROE 面板数据。你的研究方向不同,但六步法的逻辑完全一样——只需替换变量。以下是三个方向的基准回归设定参考:

【金】资本结构决定因素 ​

研究问题:公司特征如何影响资本结构(资产负债率)?三大理论假说的回归检验。

* -- 【金】资本结构基准回归 --
* 理论假说:
*   权衡理论 -> 盈利能力强(roe^) -> 负债率v(内源融资优先)
*   优序融资 -> 盈利能力强(roe^) -> 负债率v(同方向,但机制不同)
*   市场择时 -> 市值账面比(mtb^) -> 负债率v(股价高时倾向股权融资)
*
* 变量:lev(资产负债率)= β0 + β1·size + β2·roe + β3·mtb + β4·tangibility + ε
reg lev size roe mtb tangibility, vce(robust)
estat hettest
estat vif
【险】农业保险需求决定因素 ​

研究问题:农户特征如何影响农业保险参与决策?

* -- 【险】农业保险需求(因变量连续:保费支出/保额比)--
* 理论假说:
*   风险厌恶(risk_aversion^) -> 投保意愿^
*   损失厌恶(loss_aversion^) -> 对保险的需求^
*   收入(income^) -> 支付能力^ -> 投保^
*
* 变量:ins_premium = β0 + β1·risk_aversion + β2·loss_aversion + β3·income + β4·farm_size + ε
reg ins_premium risk_aversion loss_aversion income farm_size, vce(robust)
estat hettest
estat vif
* 注:如果因变量是 0/1(是否投保),则应改用 logit/probit
【农】微型金融贷款可得性 ​

研究问题:联合责任机制和动态激励如何影响农户贷款可得性?

* -- 【农】微型金融贷款可得性 --
* 理论假说:
*   联合责任(group_loan=1) -> 贷款可得性^(同伴监督降低违约率)
*   动态激励(repeat_borrower) -> 贷款额度^(声誉效应)
*
* 变量:loan_access = β0 + β1·group_loan + β2·repeat_borrower + β3·income + β4·education + ε
reg loan_access group_loan repeat_borrower income education, vce(robust)
estat hettest
estat vif
estat ovtest

跟做练习 1 ​

操作步骤:

  1. 打开你的研究文件夹,确认 data/clean/bank_panel.dta 存在(如不存在,从第 1 章 §1.4 重新生成)

  2. 新建 do 文件 code/ch09_exercise1_ols_diagnosis.do

  3. 依次完成以下六步:

    • Step A:use "data/clean/bank_panel.dta", clear

    • Step B:reg roe size leverage governance board_size(基准 OLS)

    • Step C:estat hettest + estat imtest, white(异方差诊断)→ 记录 p 值,写出判断

    • Step D:estat vif(共线性诊断)→ 记录 Mean VIF,写出判断

    • Step E:estat ovtest(设定误差诊断)→ 记录 p 值,写出判断

    • Step F:reg roe size leverage governance board_size, vce(robust)(稳健标准误)→ 对比 Step B 和 Step F 的标准误变化

  4. 在 do 文件末尾用 * 结论: 注释写出 3-5 句诊断总结

  5. 运行 do 文件,保存 log 到 output/ch09_ex1.log

自查清单:

  • 四项诊断的 p 值你都记录了吗?

  • 你能说出“p < 0.05 时应该做什么”吗?

  • 经典标准误与稳健标准误的差别大吗?如果差别大,说明什么?

  • log 文件是否完整(从 use 到最后一行命令)?

△  S9.4 提醒:这一步的所有系数、标准误、p 值必须来自你自己的 Stata 运行输出。如果你让 AI “帮我编一组回归结果”——那就是学术造假。AI 的合法用途是帮你写代码、解释输出。

§9.2 面板数据:FE 与 RE ​

核心理念:面板数据的价值在于——它让你能控制住那些观测不到、但不随时间变化的遗漏变量。这是 OLS 做不到的。固定效应(FE)解决的正是第 4 章七大效度威胁中的“不随时间变的遗漏变量”问题。

9.2.1 什么是面板数据?为什么要用面板? ​

面板数据(Panel Data)= 同一个体在多个时间点被重复观测。本手册主例 bank_panel.dta 就是 100 家银行 × 5 年(2020—2024)= 500 条观测的面板。

* -- 声明面板数据结构 --
use "data/clean/bank_panel.dta", clear
xtset bank_id year
* 输出解读:
*   panel variable:  bank_id (strongly balanced)
*   time variable:   year
*   series:          2020 2021 2022 2023 2024
*   delta:           1 unit
*
* "strongly balanced" = 每个银行都有完整 5 年数据(无缺失期)
* 如果出现 "weakly balanced" = 某些个体在某些年份缺失

* 确认数据结构
xtdescribe
* 展示面板的个体数、时间跨度、是否平衡

为什么面板比纯截面好?

表 9.10 什么是面板数据?为什么要用面板?。

L3|L3|L3

数据类型 & 能控制的遗漏变量 & 不能控制的遗漏变量
截面(cross-section) & 可观测变量(放入回归) & 所有不可观测变量
面板 + FE & 可观测变量 + 不随时间变的不可观测变量 & 随时间变化的不可观测变量
面板 + FE + 时间效应 & 上述 + 不随个体变的时间冲击 & 既随时间又随个体变的遗漏\

[提示] 与第 4 章的对接:第 4 章列出内部效度七大威胁——历史 / 成熟 / 测验效应 / 仪器变化 / 统计回归 / 选择偏差 / 样本流失。FE 主要解决的是**选择偏差中“不随时间变的遗漏变量”**这一子类(例如:银行的企业文化、所在地区的金融生态——你观测不到它们,但它们 5 年内基本不变)。

9.2.2 组内估计(Within/FE)vs GLS 随机效应(RE) ​

固定效应(FE)的核心思路:对每个变量减去其个体均值(去均值化),从而消灭所有不随时间变化的个体特征——无论你是否观测到它们。

math
y_{it} - \bar{y}_i = \beta_1(x_{1it} - \bar{x}_{1i}) + \cdots + (\varepsilon_{it} - \bar{\varepsilon}_i)

随机效应(RE)的核心思路:假设个体效应 ui 与解释变量不相关(E(ui∣xit)=0),用 GLS 加权平均组内和组间信息,比 FE 更高效(标准误更小)。

表 9.11 组内估计(Within/FE)vs GLS 随机效应(RE)。

L3|L3|L3

维度 & FE(固定效应) & RE(随机效应)
关键假设 & 个体效应与解释变量可以相关 & 个体效应与解释变量不相关
估计方法 & 组内去均值后 OLS & GLS(利用组内+组间信息)
效率 & 较低(只用组内变异) & 较高(信息利用更充分)
一致性 & 假设更弱,几乎总是一致 & 假设强,若违反则不一致
能估计不随时间变的变量吗? & ❌ 不能(被去均值消除了) & ✅ 能
适用场景 & 不确定个体效应是否与 x 相关时 & 有理论依据支持个体效应与 x 无关时\

* -- FE 与 RE 估计(沿用第 1 章 bank_roe 三模型)--
xtset bank_id year

* 模型 2:固定效应(FE)
xtreg roe size leverage governance board_size, fe
estimates store m2_fe
* 输出关键指标:
*   R-sq: within = 0.XXX  <- 组内解释力(FE 的核心指标)
*   F test that all u_i=0: F(99, 396) = XX.XX, Prob > F = 0.0000
*   -> p < 0.05 说明个体效应整体显著,FE 比混合 OLS 合适

* 模型 3:随机效应(RE)
xtreg roe size leverage governance board_size, re
estimates store m3_re
* 输出关键指标:
*   corr(u_i, X) = 0  <- RE 假设该值为 0
*   sigma_u / sigma_e 比例 <- 个体效应占总方差的比例

9.2.3 Hausman 检验:FE 还是 RE? ​

Hausman 检验是FE vs RE 的裁判——它检验的核心问题是:个体效应 ui 是否与解释变量相关?

* -- Hausman 检验 --
hausman m2_fe m3_re
* 原假设 H0:FE 和 RE 的系数差异不系统(即个体效应与 x 不相关 -> RE 一致且高效)
* 备择 H1:差异系统(个体效应与 x 相关 -> RE 不一致 -> 必须用 FE)
*
* 输出解读:
*   chi2(4) = (b-B)'[(V_b-V_B)^(-1)](b-B) = XX.XX
*   Prob > chi2 = 0.XXXX
*
* 判读规则:
*   p < 0.05 -> 拒绝 H0 -> 选 FE(个体效应与解释变量相关,RE 有偏)
*   p > 0.05 -> 不拒绝 H0 -> 选 RE(更高效且无偏)
*   p ≈ 0.05(边界)-> 保守起见选 FE

* -- Hausman 检验的注意事项 --
* 1. 必须先 estimates store 两个模型的结果
* 2. 如果 Hausman 报 "not positive definite" -> 通常意味着 RE 有问题,直接选 FE
* 3. Hausman 检验的前提是 FE 本身一致——如果 FE 也不一致(如存在时变遗漏变量),
*    Hausman 结果无意义 -> 需要 IV/DID 等更强识别策略(§9.3-§9.4)

Hausman 检验决策表:

表 9.12 Hausman 检验:FE 还是 RE?。

L4|L4|L4|L4

Hausman p 值 & 结论 & 选择 & 理由
p < 0.01 & 强烈拒绝 H0 & FE & 个体效应与 x 高度相关
0.01 ≤ p < 0.05 & 拒绝 H0 & FE & 存在相关性,RE 不一致
0.05 ≤ p < 0.10 & 边界 & FE(保守) & 宁可牺牲效率也要一致性
p ≥ 0.10 & 不拒绝 H0 & RE & 未发现相关性证据,RE 更高效\

9.2.4 BP-LM 检验:RE 还是混合 OLS? ​

Hausman 回答了“FE vs RE”。但还有一个前置问题:RE 比不用面板信息(混合 OLS)更好吗? Breusch-Pagan Lagrange Multiplier 检验回答这个问题。

* -- BP-LM 检验(需要先安装 xttest0)--
* ssc install xttest0    // 首次使用需安装

* 先跑 RE 模型
xtreg roe size leverage governance board_size, re

* BP-LM 检验
xttest0
* 原假设 H0:σ²_u = 0(无个体效应 -> 混合 OLS 即可)
* 备择 H1:σ²_u > 0(存在个体效应 -> RE 或 FE 优于混合 OLS)
*
* 输出解读:
*   Breusch and Pagan Lagrangian Multiplier Test for random effects
*   chibar2(01) = XX.XX
*   Prob > chibar2 = 0.XXXX
*
* 判读规则:
*   p < 0.05 -> 存在显著个体效应 -> RE/FE 优于混合 OLS
*   p > 0.05 -> 个体效应不显著 -> 混合 OLS 足够

完整的面板模型选择流程:

Step 1: 混合 OLS vs RE -> BP-LM 检验(xttest0)
        +-- p > 0.05 -> 用混合 OLS(无面板效应)
        +-- p < 0.05 -> 进入 Step 2

Step 2: FE vs RE -> Hausman 检验
        +-- p < 0.05 -> 用 FE
        +-- p > 0.05 -> 用 RE

9.2.5 reghdfe:高维固定效应的高效实现 ​

当面板数据量大(如 100 家银行 × 5 年 = 500 obs 还好,但 3000 家企业 × 10 年 = 30000 obs)时,传统 xtreg, fe 计算速度慢。reghdfe 是社区开发的高效替代,还能同时吸收多维固定效应。

* -- reghdfe 高维固定效应 --
* ssc install reghdfe    // 首次使用需安装
* ssc install ftools     // reghdfe 依赖 ftools

* 基本用法(等价于 xtreg, fe 但更快)
reghdfe roe size leverage governance board_size, absorb(bank_id) vce(cluster bank_id)
* absorb(bank_id) = 吸收银行个体固定效应
* vce(cluster bank_id) = 聚类稳健标准误

* reghdfe vs xtreg 结果对比(应该完全一致)
xtreg roe size leverage governance board_size, fe vce(cluster bank_id)
* -> 对比系数和标准误,验证两种实现等价

* reghdfe 的优势:
*   1. 速度:大样本比 xtreg 快 10-100 倍
*   2. 多维 FE:可同时吸收多个固定效应维度
*   3. 灵活:支持 partial out 后的 F 检验

9.2.6 双向固定效应(个体 + 时间) ​

现实中,不仅银行之间有不同的“先天条件”(个体效应),不同年份也有共同的宏观冲击(时间效应,如 2020 年疫情、2023 年利率下调)。双向固定效应同时控制两者。

* -- 双向固定效应 --
* 方法 1:reghdfe 直接吸收(推荐,最简洁)
reghdfe roe size leverage governance board_size, ///
    absorb(bank_id year) vce(cluster bank_id)
estimates store m4_twoway

* absorb(bank_id year) = 同时吸收个体FE和时间FE
* 含义:每家银行有自己的截距,每年也有自己的截距

* 方法 2:xtreg + 时间虚拟变量(等价写法,便于理解)
tab year, gen(yr_)           // 生成年份虚拟变量 yr_2018-yr_2023
xtreg roe size leverage governance board_size yr_2019-yr_2023, ///
    fe vce(cluster bank_id)
estimates store m4_twoway_xt

* 两种方法结果完全一致(系数、标准误相同)
* reghdfe 更简洁,尤其当维度多时(如 absorb(bank_id year province))

* -- 四种模型对比表 --
esttab m1_pooled m2_fe m3_re m4_twoway using "output/table_9_2.tex", ///
    replace b(%9.3f) se(%9.3f) scalars("r2_w Within R²") ///
    mtitles("混合OLS" "FE" "RE" "双向FE") ///
    stats(N r2 r2_w, labels("观测数" "R²" "Within R²")) ///
    note("标准误聚类于银行层面;* p<0.10, ** p<0.05, *** p<0.01")

与第 4 章效度威胁的完整对接:

表 9.13 双向固定效应(个体 + 时间)。

L3|L3|L3

模型 & 控制的效度威胁(第 4 章) & 不能控制的
混合 OLS & 仅可观测变量 & 所有不可观测因素
FE(个体) & 不随时间变的遗漏变量(如银行文化、地域特征) & 随时间变化的遗漏(如管理能力变动)
双向 FE(个体+时间) & 上述 + 不随个体变的时间冲击(如宏观政策) & 既随时间又随个体变的遗漏(如银行特定的行业趋势)
IV(§9.3) & 遗漏变量 + 反向因果 & 依赖工具变量的有效性
DID(§9.4) & 历史效应 + 选择偏差 & 依赖平行趋势假设\

9.2.7 面板分析完整工作流(模板) ​

* ======================================================
* §9.2 面板分析完整流程模板
* ======================================================
clear all
set more off
capture log close
log using "output/ch09_panel_analysis.log", replace

% --- 0. 数据加载与面板设定 ---
use "data/clean/bank_panel.dta", clear
xtset bank_id year
* 检查面板结构:平衡/非平衡、时间跨度
xtdes

% --- 1. 描述统计 ---
summarize roe size leverage governance board_size car npl_ratio
pwcorr roe size leverage governance board_size, star(0.05)

% --- 2. 基准回归:四种模型 ---
* (a) 混合 OLS
reg roe size leverage governance board_size, vce(robust)
estimates store m1_pooled

* (b) 个体固定效应
reghdfe roe size leverage governance board_size, ///
    absorb(bank_id) vce(cluster bank_id)
estimates store m2_fe

* (c) 随机效应
xtreg roe size leverage governance board_size, re vce(robust)
estimates store m3_re
hausman m3_re m2_fe   // Hausman 检验:p<0.05 选 FE

* (d) 双向固定效应(个体 + 时间)
reghdfe roe size leverage governance board_size, ///
    absorb(bank_id year) vce(cluster bank_id)
estimates store m4_twoway

% --- 3. 诊断检验 ---
* 多重共线性
vif                      // VIF > 10 需警惕
* 异方差(仅混合 OLS 需要)
hettest                  // p<0.05 存在异方差 -> 用 robust
* 组内自相关
estat bgodfrey           // p<0.05 存在自相关 -> 用 cluster

% --- 4. 输出对比表 ---
esttab m1_pooled m2_fe m3_re m4_twoway using "output/table_9_2.tex", ///
    replace b(%9.3f) se(%9.3f) ///
    mtitles("混合OLS" "FE" "RE" "双向FE") ///
    stats(N r2 r2_w, labels("观测数" "R²" "Within R²")) ///
    note("标准误聚类于银行层面;* p<0.10, ** p<0.05, *** p<0.01")

log close
display "=== 面板分析完成 ==="

跟做练习 2 ​

操作步骤:

  1. 新建 do 文件 code/ch09_exercise2_panel.do

  2. 按 §9.2.7 模板完成 Step 1—Step 8

  3. 在代码中用注释记录以下判断:

    • BP-LM 的 p 值是多少?→ 结论是什么?

    • Hausman 的 p 值是多少?→ 选 FE 还是 RE?

    • 双向 FE 与单向 FE 的系数变化大吗?→ 时间效应是否重要?

  4. 运行 do 文件,确认 output/panel_four_models.rtf 已生成

  5. 打开 RTF 文件,检查四列系数是否合理(方向一致、量级相近)

进阶挑战(选做):

  • 把主例换成你自己的数据(如第 6 章下载的宏观面板),重复整个流程

  • 思考:如果你的 Hausman 检验 p = 0.03(刚好 < 0.05),你会怎么选?为什么?

自查清单:

  • xtset 输出的 “strongly balanced” 还是 “weakly balanced”?你知道差别吗?

  • FE 的 Within R² 通常比混合 OLS 的 R² 低——这是正常的吗?为什么?

  • 你的 Hausman 检验结论与第 1 章 §1.4 跑的结果一致吗?

  • 双向 FE 中 absorb(bank_id year) 吸收了 100 + 5 - 1 = 104 个参数——这对自由度有什么影响?

△  S9.4 提醒:面板分析的所有系数、Hausman 统计量、BP-LM 值必须来自你自己的 Stata 运行。AI 可以帮你理解“为什么选 FE”,但不能替你“编一个 Hausman p 值”。

§9.3—§9.5 方法选择决策树(识别策略总览)

📐 结构图示(书版示意图的文字要点)

  1. tikzpicture
  2. ->,thick
  3. 是否担心\内生性?
  4. 选择偏差是否\只来自可观测变量?
  5. 有无可识别的\外生变化?
  6. 是否有政策\断点或门槛?
  7. DID(前后 + 对照)\(§9.4)
  8. 否

图 9.2 因果识别策略决策树——从“是否有内生性”出发,按“选择偏差是否可观测 / 是否有外生变化 / 是否有断点”层层判断。

§9.3 工具变量法(IV/2SLS) ​

核心理念:当解释变量与误差项相关(内生性)时,OLS 估计有偏且不一致。工具变量法的核心思想是——找到一个“外生推手”,它只通过影响内生变量来间接影响结果变量,从而把内生变量中“干净”的部分分离出来。

9.3.1 内生性的三大来源 ​

在 §9.1 的 OLS 五大经典假设中,我们要求 E(ε|X) = 0——即解释变量与误差项不相关。当这个假设被违反时,就出现了内生性(endogeneity)。三大来源:

表 9.14 内生性的三大来源。

L4|L4|L4|L4

来源 & 机制 & 金融例子 & 后果
遗漏变量偏误 & 同时影响 X 和 Y 的变量未被纳入模型 & 银行管理层能力同时影响治理水平(governance)和盈利能力(roe),但“能力”无法观测 & β̂ 有偏且不一致
反向因果 & Y 反过来影响 X & 盈利好的银行有更多资源改善治理 → 治理好;但治理好也促进盈利 → 双向因果 & β̂ 有偏且不一致
测量误差 & X 的度量包含噪声 & 问卷自评“金融素养”得分有系统性偏差 & β̂ 衰减偏误(attenuation bias)\

[重点] 判断内生性的经验法则:如果你的核心解释变量是“行为”(如投保、贷款、参加培训)或“制度特征”(如治理水平、股权结构),几乎一定有内生性——因为选择和行为本身就是非随机的。

9.3.2 有效工具变量的两大条件 ​

一个合格的工具变量 Z 必须同时满足:

条件 1:相关性(Relevance)
   Z 与内生变量 X 显著相关
   -> 可检验:第一阶段 F 统计量 > 10(Stock & Yogo, 2005)

条件 2:排他性约束(Exclusion Restriction)
   Z 只通过 X 影响 Y,不能有直接影响 Y 的其他路径
   -> 不可检验!只能靠经济理论和制度逻辑论证

图形化理解:

         Z(工具变量)
         |
         | ① Z -> X(相关性:可检验)
         v
    X(内生变量)-------> Y(结果变量)
         ▲               ▲
         |               |
         +--- U ---------+  ② 遗漏变量 U 同时影响 X 和 Y(内生性来源)

   排他性约束:Z 到 Y 没有除了经过 X 之外的箭头(即 Z ⊥ U)

9.3.3 两阶段最小二乘法(2SLS)的 Stata 实现 ​

主例:研究公司治理(governance)对银行盈利能力(roe)的影响。我们担心 governance 是内生的(遗漏变量 + 反向因果),使用同行业其他银行的平均治理水平(industry_avg_governance)作为工具变量。

IV 的逻辑:同行业其他银行的平均治理水平与本研究银行的治理水平相关(行业示范效应、监管标准趋同),但不会直接影响本银行的 ROE(排他性约束:其他银行的治理水平只通过“行业规范压力”影响本行治理,而不直接影响本行利润)。

* -- §9.3 IV/2SLS 完整流程 --
* 数据:bank_panel.dta(100家上市银行×5年面板)
use data/clean/bank_panel.dta, clear
xtset bank_id year

* 第一步:OLS 基准(作为对比)
reg roe size leverage governance board_size, vce(cluster bank_id)
est store m1_ols

* 第二步:2SLS 估计
* 语法:ivregress 2sls 因变量 外生变量列表 (内生变量 = 工具变量), 选项
ivregress 2sls roe size leverage board_size ///
    (governance = industry_avg_governance), ///
    vce(cluster bank_id)
est store m2_iv

* 输出解读:
*   governance 的 IV 系数 = 利用工具变量"提纯"后的因果效应估计
*   若 IV 系数 > OLS 系数 -> OLS 可能低估了治理的因果效应(衰减偏误或反向因果稀释)
*   若 IV 系数 < OLS 系数 -> OLS 可能高估(遗漏变量正向偏误)

9.3.4 弱工具变量检验:第一阶段 F 统计量 ​

* -- 第一阶段诊断 --
estat firststage

* 输出解读:
*   关注 F 统计量(Kleibergen-Paap rk Wald F statistic)
*   判读规则:
*     F ≥ 10  -> 非弱工具变量,2SLS 估计可信(Stock & Yogo 临界值)
*     F < 10  -> 弱工具变量!2SLS 估计可能有严重偏误,甚至比 OLS 更差
*
*   示例输出:
*   Kleibergen-Paap rk Wald F statistic = 15.32
*   判读:F = 15.32 > 10 -> 非弱工具,可以信赖 2SLS 结果
*
*   若 F = 3.8 < 10:
*   -> 工具变量与内生变量的相关性太弱
*   -> 需要换一个更强的工具变量,或放弃 IV 策略

弱工具变量的后果(务必理解):

表 9.15 弱工具变量检验:第一阶段 F 统计量。

L3|L3|L3

第一阶段 F & 后果 & 应对
F > 10 & 正常,2SLS 一致且近似正态 & 直接报告
5 < F < 10 & 灰色地带,可能有有限样本偏误 & 补充报告 Anderson-Rubin 置信区间
F < 5 & 严重弱工具,2SLS 可能比 OLS 更糟 & 放弃该 IV,另寻工具变量\

9.3.5 过度识别检验(Sargan / Hansen J) ​

当你有多个工具变量时(工具变量数 > 内生变量数),可以检验“多余的工具变量是否满足排他性约束”:

* -- 过度识别检验(使用两个工具变量) --
ivregress 2sls roe size leverage board_size ///
    (governance = industry_avg_governance regulatory_pressure), ///
    vce(cluster bank_id)

* Hansen J 检验(异方差稳健版,优先使用)
estat overid

* 输出解读:
*   H0:所有工具变量均满足排他性约束(即过度识别约束有效)
*   p > 0.05 -> 不能拒绝 H0 -> 工具变量整体可接受
*   p < 0.05 -> 拒绝 H0 -> 至少有一个工具变量不满足排他性,需要逐一排查
*
*   示例:Hansen J chi2(1) = 0.82, p = 0.365
*   判读:p = 0.365 > 0.05 -> 过度识别约束不被拒绝,两个 IV 整体有效

△  注意:当工具变量数 = 内生变量数时(恰好识别,just-identified),过度识别检验不可用——此时排他性约束完全无法被统计检验,只能靠经济逻辑论证。

9.3.6 金融学常用工具变量举例 ​

表 9.16 金融学常用工具变量举例。

L4|L4|L4|L4

IV 类型 & 具体变量 & 适用场景 & 排他性论证思路
行业/地区均值 & 同行业其他企业的平均 X & 企业层面内生变量(治理、杠杆、研发投入) & 其他企业的特征不直接影响本企业结果
政策冲击 & 政策试点的批次/时间差异 & 政策评估(数字金融试点、绿色信贷政策) & 批次分配由行政因素决定,与企业绩效无直接关联
地理变量 & 到金融中心距离、海拔、河流密度 & 金融可得性、保险覆盖 & 地理是“天然的”,不受个体行为影响
历史变量 & 历史上的金融基础设施(如民国钱庄数量) & 当前金融发展水平 & 历史变量通过路径依赖影响当前制度,但不直接影响当前个体结果
制度变量 & 法律起源、监管框架差异 & 跨国/跨地区比较 & 制度由历史决定,不由个体企业选择\

[提示] AI 辅助研究提示:你可以把研究假设贴给 AI 问“这个场景可能的工具变量有哪些?排他性约束是否合理?”——但最终的 IV 选择和论证是你的学术判断,不能外包给 AI(S9.4 红线)。

跟做练习 3 ​

任务:用 bank_panel.dta 完成 IV/2SLS 全流程并诊断。

  1. 打开数据并设定面板:use data/clean/bank_panel.dta, clear + xtset bank_id year

  2. 运行 OLS 基准:reg roe size leverage governance board_size, vce(cluster bank_id),记录 governance 系数

  3. 运行 2SLS:

ivregress 2sls roe size leverage board_size ///
    (governance = industry_avg_governance), vce(cluster bank_id)
  1. 检验弱工具变量:estat firststage,记录 F 值并判断是否 > 10

  2. 对比 OLS 与 IV 系数:governance 的系数变大还是变小?尝试解释方向

  3. (进阶)如果你能找到第二个工具变量,加入后运行 estat overid,解读 Hansen J 的 p 值


回指第4章效度威胁 ​

第 4 章 §4.2 定义了七大内部效度威胁。工具变量法主要解决以下威胁:

表 9.17 回指第4章效度威胁。

L2|L2

第4章效度威胁 & IV 如何应对
选择偏差(Selection) & 当“参与”是非随机的(如自愿改善治理的银行本身就是好银行),IV 通过外生变异打破自选择,使得“被工具推动改善治理”的部分近似随机
历史(History)(间接) & 若外部事件同时影响了 X 和 Y,一个好的 IV 与这些事件无关(排他性约束),因此 IV 估计不受历史干扰\

用第 4 章的语言说:IV 把“是不是它干的”这个问题,转化为“有没有一个外生的推手能证明是它干的”。如果第一阶段 F > 10 且排他性论证站得住,你就获得了对选择偏差和遗漏变量偏误的有效防御。

§9.4 双重差分法(DID) ​

核心理念:双重差分是政策评估的“黄金标准”之一。它的直觉极为简洁——用对照组的“自然变化”来扣除处理组的“自然变化”,剩下的就是政策的因果效应。DID 的本质是一个 2×2 因子设计的交互项。

9.4.1 DID 直觉:差分掉共同趋势 ​

场景:2019 年某省推行“数字金融示范区”政策,你想知道这个政策是否提高了当地银行的 ROE。

                    政策前(2018)    政策后(2020)    变化
   处理组(示范省)     roe_T,pre       roe_T,post     ΔT = roe_T,post - roe_T,pre
   对照组(非示范省)   roe_C,pre       roe_C,post     ΔC = roe_C,post - roe_C,pre

   DID 估计量 = ΔT - ΔC
              =(处理组前后差)-(对照组前后差)

为什么需要“双重”差分?

  • 只做一次差分(处理组前后差 ΔT):包含了政策效应 + 时间趋势(宏观经济好转、行业整体复苏等)

  • 只做截面差分(处理后处理组 - 对照组):包含政策效应 + 两组先天差异

  • 双重差分:ΔT - ΔC 把“共同时间趋势”和“先天水平差异”同时扣掉

[重点] 关键假设:平行趋势——如果没有政策干预,处理组和对照组的结果变量应该沿着平行的轨迹变化。不要求水平相同,只要求变化趋势相同。

9.4.2 2×2 因子设计本质(★ 本节核心) ​

回指 §9.0:我们在 GLM 统摄视角中学过 2×2 因子设计的一般线性模型:

math
y = \beta_0 + \beta_1 \cdot x_1 + \beta_2 \cdot x_2 + \beta_3 \cdot x_1 \cdot x_2 + \varepsilon

其中 β1、β2 是主效应,β3 是交互效应。

DID 就是这个公式的直接应用:

表 9.18 2×2 因子设计本质( 本节核心)。

L3|L3|L3

因子设计术语 & DID 术语 & 含义
x1(因子1) & treat(处理组虚拟变量) & 1 = 处理组,0 = 对照组
x2(因子2) & post(时间虚拟变量) & 1 = 政策后,0 = 政策前
β1(主效应1) & treat 系数 & 处理组与对照组的先天水平差异
β2(主效应2) & post 系数 & 共同时间趋势
β3(交互效应) & treat × post 系数 & = DID 估计量 = 政策因果效应\

“回归系数 β1 和 β2 提供了主效应的效应规模估计值,β3 则提供了交互效应的效应规模估计值。”

DID 回归方程:

math
roe_{it} = \beta_0 + \beta_1 \cdot treat_i + \beta_2 \cdot post_t + \beta_3 \cdot (treat_i \times post_t) + \gamma \cdot X_{it} + \varepsilon_{it}
* -- 2×2 DID 基本回归 --
use data/clean/bank_panel.dta, clear

* 生成 DID 所需变量
gen treat = (province == "示范省")        /* 处理组标记 */
gen post  = (year >= 2019)                /* 政策后标记 */
gen did   = treat * post                  /* 交互项 = DID 估计量 */

* 运行 DID 回归
reg roe treat post did size leverage, vce(cluster bank_id)

* 输出解读:
*   did 的系数 β3 = 政策的因果效应(ATT)
*   若 β3 = 1.2, p < 0.05 -> 示范区政策使银行 ROE 提高约 1.2 个百分点
*   treat 系数 = 两组先天差异(不随时间变)
*   post 系数 = 共同时间趋势(两组共享)

关键警示:“如果 β3 是显著的……我们就不能显著地解读出课程类型(β1)或者教学时间(β2)的独立效应,因为这两个效应不能被区分开来。只有当交互效应不显著的时候,主效应才能被解读出来。”

映射到 DID:当交互项 treat×post 显著时(即政策有效应),treat 和 post 的主效应系数不应单独解读为“处理组特征”或“时间趋势”——它们已经被交互项“吸收”了部分含义。只有在 DID 估计量不显著时,treat 和 post 才可以作为独立的组间差异和时间趋势来解读。

9.4.3 平行趋势假设与事件研究法 ​

平行趋势是 DID 的命门。如何检验?——事件研究法(Event Study):把政策前每一期都设为虚拟变量,看政策前处理组与对照组的差异是否为零。

* -- 事件研究法检验平行趋势 --
* 需要安装:ssc install eventstudyinteract

* 生成相对时间虚拟变量(以政策前1期为基准期)
gen rel_time = year - 2019   /* -3, -2, -1, 0, 1, 2 */

* 用 eventstudyinteract 估计动态效应
eventstudyinteract roe L3.rel_time L2.rel_time L1.rel_time ///
    F0.rel_time F1.rel_time F2.rel_time, ///
    vce(cluster bank_id) treat(treat) base(0)
* L3.rel_time = 政策前第3期, L1.rel_time = 政策前第1期(基准期省略)
* F0.rel_time = 政策当期, F1.rel_time = 政策后第1期

* 绘制事件研究图(动态效应图)
coefplot, keep(L3.rel_time L2.rel_time L1.rel_time ///
    F0.rel_time F1.rel_time F2.rel_time) ///
    vertical yline(0, lpattern(dash) lcolor(red)) ///
    ciopts(recast(rcap)) ///
    xtitle("相对政策时点") ytitle("动态处理效应") ///
    title("事件研究法:平行趋势检验") ///
    note("政策前各期系数应不显著异于0")
graph export "figures/event_study.pdf", replace

* 联合检验:政策前系数是否联合为零
* eventstudyinteract 自动报告 Wald 检验
*
*   [!] 若政策前系数显著 -> 平行趋势不成立 -> DID 结果不可信
*   -> 需要换对照组、缩短时间窗口、或改用合成控制法

判断标准:

表 9.19 平行趋势假设与事件研究法。

L3|L3|L3

检验结果 & 判读 & 下一步
政策前各期系数联合 F 检验 p > 0.10 & 平行趋势成立 & 放心使用 DID
个别期显著但无趋势 & 可能是随机波动 & 补充安慰剂检验
政策前呈系统性趋势 & 平行趋势不成立 & 换方法(合成控制/匹配+DID)\

9.4.4 多期/交错 DID 与异质性处理效应 ​

现实中,政策往往不是“一刀切”同时实施——不同地区在不同年份被纳入试点(交错处理,staggered adoption)。传统双向固定效应(TWFE)DID 在交错处理 + 异质性处理效应时会产生偏误(Goodman-Bacon, 2021; de Chaisemartin & D’Haultfœuille, 2020)。

* -- 交错 DID:使用 did_multiplegt --
* 需要安装:ssc install did_multiplegt

* 假设不同银行在不同年份受到政策冲击
* first_treat: 每个个体首次受处理的年份(从未处理的设为 0 或极大值)

did_multiplegt roe bank_id year treat, ///
    robust_dynamic dynamic(3) placebo(3) ///
    breps(200) cluster(bank_id)

* 输出解读:
*   "Average cumulative effect" = 累积平均处理效应
*   "Dynamic effect" 按事件时间报告 -> 可画出事件研究图
*   与传统 TWFE 对比:若两者差异大 -> 存在异质性处理效应
*
*   [!] 异质性处理效应警示:
*   如果早期处理者的效应 ≠ 晚期处理者的效应
*   -> TWFE 的 DID 系数是各 2×2 DID 的加权平均,权重可能为负!
*   -> 此时必须使用 did_multiplegt / callaway / sun_abraham 等新方法

9.4.5 标准误聚类到处理层面 ​

DID 的标准误必须聚类到处理分配的层面(treatment assignment level),而不是个体层面:

* -- 正确 vs 错误的标准误 --

* [x] 错误:聚类到个体(bank_id)—— 如果政策是省级分配的
reg roe treat post did size leverage, vce(cluster bank_id)

* [v] 正确:聚类到政策分配层面(province)
reg roe treat post did size leverage, vce(cluster province)

* 判断规则:
*   政策在哪个层面分配 -> 就聚类到哪个层面
*   例:省级试点 -> cluster(province)
*       行业级监管 -> cluster(industry)
*       银行级处理 -> cluster(bank_id)
*
*   聚类层级越高,有效样本量越小,标准误越大
*   Abadie et al. (2023):当处理组数量少时,应考虑 wild bootstrap

跟做练习 4 ​

任务:用 bank_panel.dta 完成一个完整的 DID 分析。

  1. 构造处理变量:假设 bank_id 1-30 的银行在 2019 年被纳入“数字治理示范行”,生成 treat、post、did 三个变量

  2. 运行 2×2 DID 回归:reg roe treat post did size leverage, vce(cluster bank_id)

  3. 解读交互项 did 的系数——这是政策的因果效应吗?为什么?

  4. 用事件研究法检验平行趋势:生成政策前各期的 treat×year 交互虚拟变量,用 reghdfe 估计

  5. 画出事件研究图(coefplot):政策前系数应围绕零线波动

  6. (进阶)思考:如果不同银行在 2018、2019、2020 不同年份被纳入示范,你应该用什么方法?为什么传统 TWFE 可能有问题?


回指第4章效度威胁 ​

第 4 章 §4.2 的七大内部效度威胁中,DID + 平行趋势主要解决以下两条:

表 9.20 第4章效度威胁 / DID 如何应对速查表。

L2|L2

第4章效度威胁 & DID 如何应对
历史(History) & “你的研究期恰好赶上 LPR 下调 / 疫情 / 房地产调控”——DID 通过对照组吸收了所有共同的外部事件冲击。只要这些事件同等地影响了处理组和对照组(平行趋势),差分后就被消除
选择偏差(Selection) & “试点县本来就是省里挑的先进县”——DID 不要求处理组和对照组水平相同(treat 主效应吸收了先天差异),只要求变化趋势相同。因此,即便处理组先天更优秀,只要没有政策时两组会平行变化,DID 估计就是无偏的\

用第 4 章的语言说:DID 把“历史威胁”交给对照组去吸收,把“选择偏差”转化为“平行趋势是否成立”这个可检验的问题。这正是为什么 DID 在政策评估中如此强大——它不要求消除选择偏差的来源,只要求偏差的时间模式是可预测的。

§9.5 倾向得分匹配(PSM)与断点回归(RDD) ​

核心理念:PSM 和 RDD 都试图在观测数据中“模拟随机实验”——PSM 通过匹配可观测特征构造“近似等价”的对照组;RDD 利用制度规则的断点,在断点附近创造“近似随机化”的局部比较。


Part A:倾向得分匹配(PSM) ​

9.5.1 选择偏差与可观测对照组的构造 ​

问题:在第 4 章 §4.2 中,我们把**选择偏差(Selection)**称为“经济研究的头号杀手”——自愿参与保险、贷款、培训的人与不参与的人从一开始就不一样。

PSM 的核心思想:

理想状态(RCT):随机分配 -> 处理组 ≈ 对照组(所有特征均衡)
现实状态(观测数据):自选择 -> 处理组 ≠ 对照组

PSM 的折中方案:
  1. 用可观测特征(规模、杠杆、地区、行业...)估计"参与概率"(倾向得分)
  2. 给每个处理组个体找一个倾向得分最接近的对照组个体(匹配)
  3. 匹配后,两组在可观测特征上"近似等价"
  4. 比较匹配后的结果变量差异 = ATT(处理组的平均处理效应)

△  PSM 的根本局限:它只能平衡可观测的特征。如果存在不可观测的混淆变量(如“管理层能力”“风险偏好”),PSM 无法解决——此时需要 IV 或 DID。

9.5.2 Stata 实现:psmatch2 与 teffects psmatch ​
* -- PSM 完整流程 --
use data/clean/bank_panel.dta, clear

* 假设:treat = 1 表示银行实施了数字化转型
* 目标:评估数字化转型对 ROE 的因果效应

* --- 方法一:psmatch2(经典,输出详细) ---
* 需要安装:ssc install psmatch2
* 第一步:估计倾向得分并匹配(1:3 近邻匹配)
psmatch2 treat size leverage car board_size, outcome(roe) ///
    neighbor(3) common caliper(0.05)
*   treat = 处理变量(数字化转型=1)
*   neighbor(3) = 每个处理单元匹配3个对照单元
*   common = 限制在共同支撑域内
*   caliper(0.05) = 倾向得分差异超过0.05的不匹配

* 查看匹配结果
pstest size leverage car board_size, both graph
* 输出:匹配后各变量的标准化偏差(|SB|)和 t 检验

* --- 方法二:teffects psmatch(现代,更规范) ---
teffects psmatch (roe) (treat size leverage car board_size), ///
    nneighbor(3) caliper(0.05)
* 输出解读:
*   ATET = 处理组平均处理效应(与 psmatch2 的 ATT 含义相同)
*   teffects 自动报告标准误和置信区间
9.5.3 匹配质量诊断 ​

匹配不是“跑一下就完了”——你必须证明匹配后两组确实“近似等价”。

* -- 诊断 1:共同支撑域(Common Support) --
* psmatch2 运行后自动输出
sum _pscore if treat == 1   /* 处理组倾向得分范围 */
sum _pscore if treat == 0   /* 对照组倾向得分范围 */

* 判断:两组倾向得分分布应有大面积重叠
* 若处理组最低分 > 对照组最高分 -> 无共同支撑,匹配失败

* -- 诊断 2:平衡性检验(Balance Test) --
pstest size leverage roa cost_income, t(treat)
* 预期输出:
*   Variables   |  Std. Bias  |  t-stat  |  p-value
*   ------------|-------------|----------|---------
*   size        |    3.2%     |   0.45   |  0.653
*   leverage    |    5.1%     |   0.78   |  0.436
*   roa         |    2.8%     |   0.31   |  0.758
*   cost_income |    4.6%     |   0.62   |  0.535
*   判断:所有变量 |SB| < 10%

* -- 诊断 3:匹配前后偏差对比图 --
pstest size leverage roa cost_income, t(treat) graph
* 预期:匹配后各变量的标准化偏差柱状图明显缩短

* -- 判断标准 --
*   |SB| < 10%
*   -> 平衡性良好,匹配有效
*   |SB| > 10% -> 该变量未平衡,需要调整匹配方法
*   (如:增加匹配数 neighbor(3)、改用核匹配 kernel、加入更多协变量)

匹配质量诊断清单:

表 9.21 Part A:倾向得分匹配(PSM)。

L4|L4|L4|L4

诊断项 & 合格标准 & 不合格的后果 & 补救措施
共同支撑域 & 两组倾向得分分布重叠 ≥ 90% & 大量样本被丢弃,外部效度下降 & 修剪(trimming)或换匹配方法
标准化偏差 & 匹配后所有协变量 & SB & < 10%
匹配后样本量 & ATT 估计基于足够样本 & 统计检验力不足 & 放宽匹配容差或改用 IPW
Rosenbaum 敏感性分析 & Γ > 1.5 时结论仍稳健 & 存在潜在不可观测混淆 & 承认局限,讨论方向\


Part B:断点回归(RDD) ​

9.5.4 RDD 直觉:断点附近近似随机化 ​

场景:某省规定“资本充足率 ≥ 10.5% 的银行可获得创新业务牌照”。你想知道获得牌照是否提高了银行 ROE。

       获得牌照概率
  1.0 -----------------+
                        |  <- 断点(cutoff = 10.5%)
  0.0 ------------------+
       --------------------------
       8%    9%   10%  10.5%  11%  12%
                    资本充足率(running variable)

  核心直觉:
  资本充足率 = 10.4% 的银行 vs 10.6% 的银行
  -> 两者在其他方面几乎一样(0.2% 的差异可能是随机波动)
  -> 但一个没拿到牌照,一个拿到了
  -> 比较断点两侧的 Y = 近似随机实验的局部因果效应

RDD 的识别假设:在断点附近,个体无法精确操纵(manipulate)自己的 running variable 值。如果银行可以精确地把资本充足率调到 10.5% 以上,RDD 就不成立。

9.5.5 Stata 实现:rdrobust 与带宽选择 ​
* -- RDD 完整流程 --
use data/clean/bank_panel.dta, clear

* 假设:car = 资本充足率(running variable)
*       cutoff = 10.5(断点值)
*       roe = 结果变量

* 需要安装:ssc install rdrobust

* -- Step 1:局部线性回归(锐角断点) --
rdrobust roe car, c(10.5) p(1) h(ms) kernel(triangular)
* 预期输出:
*   RD estimates at the cutoff (car = 10.5)
*   Coef. = 0.0342   SE = 0.0128   p = 0.008
*   95% CI: [0.0091, 0.0593]
*   结论:通过资本充足率门槛的银行,ROE 显著提高约 3.4 个百分点

* -- Step 2:McCrary 密度检验(操纵检验) --
* 需安装:ssc install rddensity
rddensity car, c(10.5)
* 预期输出:
*   p-value = 0.237
*   结论:密度分布在断点处无显著跳变

* -- Step 3:图形展示 --
rdplot roe car, c(10.5) p(1) nbins(20 20) ///
    title("图 9-4  RDD 局部线性回归") ///
    ytitle("ROE (%)") xtitle("资本充足率 (%)") ///
    lineopts(lcolor(red) lwidth(medthick))
graph export "figures/rdd_robust.pdf", replace

* -- Step 4:安慰剂检验(断点偏移) --
rdrobust roe car, c(9.0) p(1) h(ms) kernel(triangular)
* 预期:在假断点处系数不显著(p > 0.10)
rdrobust roe car, c(12.0) p(1) h(ms) kernel(triangular)
* 预期:同样不显著

* -- Step 5:不同核函数稳健性 --
rdrobust roe car, c(10.5) p(1) kernel(uniform)
rdrobust roe car, c(10.5) p(1) kernel(epanechnikov)
* 预期:不同核函数下系数方向和显著性一致

* 判断标准:
*   p > 0.05 -> 断点处无密度跳变 -> 不存在操纵,RDD 有效
*   p < 0.05 -> 密度跳变 -> 个体可能在操纵 running variable -> RDD 不可信

带宽选择要点:

表 9.22 Part B:断点回归(RDD)。

L4|L4|L4|L4

带宽策略 & 优点 & 缺点 & 推荐
MSE 最优带宽(默认) & 均方误差最小,统计效率最高 & 可能有偏 & ✅ 主结果
0.5× 最优带宽 & 偏差更小 & 样本少,方差大 & 稳健性检验
2× 最优带宽 & 样本多,精度高 & 偏差可能增大 & 稳健性检验
手动固定带宽 & 透明可复现 & 可能被“挑选” & 补充报告\

9.5.6 精确断点 vs 模糊断点 ​

表 9.23 类型 / 定义 / 断点处处理概率 / 估计方法速查表。

L5|L5|L5|L5|L5

类型 & 定义 & 断点处处理概率 & 估计方法 & 金融例子
精确断点(Sharp RDD) & running variable 跨过 cutoff → 100% 获得处理 & 从 0 跳到 1 & 直接比较断点两侧 Y 的局部线性回归 & 资本充足率 ≥ 10.5% → 自动获牌照
模糊断点(Fuzzy RDD) & 跨过 cutoff → 处理概率跳升但不是 100% & 从 p1 跳到 p2(p2 > p1 但 < 1) & IV 思路:用“是否在断点以上”作为“实际是否接受处理”的工具变量 & 评分 ≥ 60 分的贷款申请“大概率”获批,但审批员有酌情权\

* -- 模糊断点 RDD(Fuzzy)--
* 当处理不是由断点唯一决定时
* 用 rdrobust 的 fuzzy 选项:以 cutoff dummy 为工具变量

* 示例:贷款审批分数 ≥ 60 分的申请"大概率"获批
rdrobust loan_amount credit_score, c(60) fuzzy(approved) ///
    kernel(triangular) p(1)

* 输出解读:
*   系数 = Wald 估计量 = (Y 在断点处的跳变) / (处理概率在断点处的跳变)
*   本质上就是 2SLS:用 1(credit_score ≥ 60) 作为 approved 的工具变量
*   -> 模糊 RDD = 局部 IV

[提示] AI 辅助研究提示:你可以问 AI “我的数据中是否存在天然的断点?”或“帮我论证 running variable 在断点处不可操纵”——但 McCrary 密度检验和带宽敏感性分析必须自己跑,AI 不能替你生成统计量(S9.4 红线)。

跟做练习 5 ​

任务 A(PSM):

  1. 打开 bank_panel.dta,定义 treat = 1 为 board_size > 中位数的银行(大董事会)

  2. 运行

  3. 检查 ATT 是否显著——大董事会是否“因果地”提高了 ROE?

  4. 运行平衡性检验:匹配后各协变量的标准化偏差是否 < 10%?

  5. 思考:PSM 能排除“不可观测的管理层能力”这一混淆因素吗?如果不能,该用什么方法?

任务 B(RDD):

  1. 假设 bank_panel.dta 中有变量 capital_ratio(资本充足率),监管红线为 10.5%

  2. 先画散点图:scatter roe capital_ratio || lowess roe capital_ratio, c(10.5)

  3. 运行 rdplot roe capital_ratio, c(10.5),目视检查断点处是否有跳变

  4. 运行 rdrobust roe capital_ratio, c(10.5),记录点估计、标准误和最优带宽

  5. 做带宽敏感性:分别用 0.5× 和 2× 带宽重跑,结论是否稳健?

  6. (进阶)运行 rddensity,判断是否存在操纵


回指第4章效度威胁 ​

第 4 章 §4.2 定义的七大内部效度威胁中,PSM 和 RDD 各自针对的核心威胁:

表 9.24 识别策略 / 对应的第4章效度威胁 / 具体机制速查表。

L3|L3|L3

识别策略 & 对应的第4章效度威胁 & 具体机制
PSM & 选择偏差(Selection) & “参加农业保险的都是风险厌恶型农户”——PSM 通过匹配可观测特征(收入、规模、教育),构造一个“在可观测维度上与处理组等价”的对照组,从而消除可观测部分的选择偏差
RDD & 选择偏差(Selection)—— 特指“自选择的断点” & “试点县本来就是省里挑的先进县”——RDD 利用制度规则的外生断点(如资本充足率门槛),在断点附近个体无法精确操纵自己的位置,因此断点两侧的比较近似随机化\

§9.6 稳健性与异质性 ​

稳健性检验工具箱(4 类工具 × 6 种威胁)

📐 结构图示(书版示意图的文字要点)

  1. tikzpicture
  2. 威胁 工具
  3. 替代变量
  4. 子样本
  5. 换估计方法
  6. 遗漏变量
  7. 反向因果
  8. 测量误差

图 9.3 6 种威胁 × 4 类工具的应对能力——同一威胁可用多种工具组合施压,但不挑好看的(参见 §9.6 三组对照原则与 S9.2 红线)。

9.6.1 三组稳健性检验:主检验 + 替换变量 + 子样本 ​

完成基准回归(§9.1-§9.5)后,你需要回答一个关键问题:我的结论对模型设定的依赖程度有多大? 稳健性检验的标准做法是“三组对照”:

表 9.25 三组稳健性检验:主检验 + 替换变量 + 子样本。

L4|L4|L4|L4

组别 & 含义 & 具体操作 & 论文报告格式
第 1 组:主检验 & 改变估计方法/控制变量集 & 加入更多控制变量、换聚类层级、换标准误类型 & “在加入 XX 控制变量后,核心系数保持显著”
第 2 组:替换变量 & 用另一种方式测量核心概念 & 替换因变量(ROE→ROA)、替换自变量(治理指数→独董比例) & “替换核心变量后,结论方向一致/不一致”
第 3 组:子样本 & 排除特定样本重新估计 & 剔除国有银行、剔除疫情年份、仅保留东部地区 & “在子样本中,效应更大/更小/不显著”\

关键原则(S9.2 红线):

  • 三组稳健性检验的结果全部如实报告,不挑好看的

  • 如果某组检验失败了(核心系数不显著),要写明“在 XX 条件下不再稳健”并讨论原因

  • 稳健性检验的目的是给读者提供信息,不是为了“通过”

* ======================================================
* §9.6 稳健性检验三组:基于 bank_panel.dta 主例
* ======================================================

use "data/clean/bank_panel.dta", clear
xtset bank_id year

* -- 第 1 组:主检验(基准 + 更多控制 + 换聚类) --
* 列 (1):基准 FE,聚类到银行层面
xtreg roe governance size leverage roa cost_income i.year, fe cluster(bank_id)
est store base

* 列 (2):增加控制变量(存款比率 dep_ratio、非息收入占比 nonii)
xtreg roe governance size leverage roa cost_income dep_ratio nonii i.year, fe cluster(bank_id)
est store more_ctrl

* 列 (3):聚类到省份层面(更保守)
xtreg roe governance size leverage roa cost_income dep_ratio nonii i.year, fe cluster(province)
est store cluster_prov

* -- 第 2 组:子样本检验 --
* 列 (4):剔除国有银行(state == 1)
xtreg roe governance size leverage roa cost_income dep_ratio nonii i.year if state == 0, fe cluster(province)
est store no_state

* 列 (5):仅 2010 年以后样本
xtreg roe governance size leverage roa cost_income dep_ratio nonii i.year if year >= 2010, fe cluster(province)
est store post2010

* -- 第 3 组:替换因变量 --
* 列 (6):因变量替换为 ROA
xtreg roa governance size leverage dep_ratio nonii i.year, fe cluster(province)
est store roa_dv

* -- 汇总输出 --
esttab base more_ctrl cluster_prov no_state post2010 roa_dv, ///
    b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) ///
    mgroups("主检验" "子样本" "替换因变量", ///
        pattern(1 0 1 0 1 1)) ///
    label booktabs ///
    addnotes("注:括号内为聚类到省份层面的稳健标准误。*** p<0.01, ** p<0.05, * p<0.1。")

输出解读要点:

  • 如果核心变量(governance)在所有列中方向和显著性一致 → 结论稳健

  • 如果某一列不显著 → 诚实报告“在剔除国有银行后效应不再显著,可能因为国有银行治理机制不同”

  • 如果方向翻转 → 严重问题,需重新审视模型设定

9.6.2 规格曲线:S9.1“不 p-hacking”的自证工具 ​

什么是规格曲线(Specification Curve)?

传统稳健性检验报告 3-5 种设定,但审稿人可能质疑:“你只挑了对你有利的设定。”规格曲线的做法是:穷举所有合理的模型设定(如所有控制变量组合),画出核心系数的分布图,让读者一目了然。

逻辑:如果你尝试了 128 种合理设定,其中 120 种都显著且方向一致 → 强证据。如果只有 20 种显著 → 你的结论可能是 p-hacking 的产物。

* ======================================================
* 规格曲线模拟:穷举控制变量子集
* ======================================================

use "data/clean/bank_panel.dta", clear
xtset bank_id year

* 定义可选控制变量池(4 个变量 -> 2^4 = 16 种组合)
global ctrl_pool "size leverage roa cost_income"

* 穷举所有组合
local n_specs = 0
tempname coef_mat
postfile `coef_mat' spec_id governance_se governance_b using spec_results, replace

forvalues i = 0/15 {
    local controls ""
    local bit3 = mod(floor(`i'/8), 2)
    local bit2 = mod(floor(`i'/4), 2)
    local bit1 = mod(floor(`i'/2), 2)
    local bit0 = mod(`i', 2)
    if `bit3' == 1  local controls "`controls' size"
    if `bit2' == 1  local controls "`controls' leverage"
    if `bit1' == 1  local controls "`controls' roa"
    if `bit0' == 1  local controls "`controls' cost_income"

    capture xtreg roe governance `controls' i.year, fe cluster(province)
    if _rc == 0 {
        local n_specs = `n_specs' + 1
        post `coef_mat' (`n_specs') (_b[governance]) (_se[governance])
    }
}
postclose `coef_mat'

* 读取结果并绘图
preserve
use spec_results, clear
sort governance_b
gen spec_num = _n

twoway scatter governance_b spec_num, ///
    msymbol(Oh) mcolor(navy) msize(small) ///
    yline(0, lcolor(red) lpattern(dash)) ///
    title("图 9-5  规格曲线:16 种控制变量组合") ///
    note("红线 = 0。所有点在红线同侧 -> 结论稳健")
graph export "figures/spec_curve.pdf", replace

给学生的话:规格曲线不是让你“找到显著的那一种”,而是展示你的结论不依赖于某一种特定设定。如果曲线在 0 两侧频繁穿越,你的结论确实不稳健——这时候诚实比显著更重要。

9.6.3 异质性分析 ​

异质性回答的问题:核心效应在不同群体间是否有差异? 这不是“换着法子凑显著”,而是探索效应的边界条件。

方法一:分组回归(bysort)

* -- 异质性:按银行类型分组 --
* bank_type: 1=国有大型, 2=股份制, 3=城商行
bysort bank_type: reghdfe roe governance size leverage, ///
    absorb(bank_id year) vce(cluster province)

* 存储分组结果
reghdfe roe governance size leverage if bank_type == 1, absorb(bank_id year) vce(cluster province)
est store het_soe
reghdfe roe governance size leverage if bank_type == 2, absorb(bank_id year) vce(cluster province)
est store het_joint
reghdfe roe governance size leverage if bank_type == 3, absorb(bank_id year) vce(cluster province)
est store het_city

方法二:交乘项(交互效应)

* -- 异质性:交乘项法(推荐,可做组间差异检验) --
* 生成交乘项
gen gov_x_soe = governance * (bank_type == 1)

reghdfe roe governance gov_x_soe size leverage, ///
    absorb(bank_id year) vce(cluster province)

* 输出解读:
*   governance 系数 = 非国有银行的基准效应
*   gov_x_soe 系数 = 国有银行相对非国有银行的增量效应
*   如果 gov_x_soe 显著 -> 治理对国有银行的效果不同于非国有银行

两种方法的选择:

  • 分组回归:直观,适合描述;但无法检验“两组系数差异是否显著”

  • 交乘项:可以检验组间差异(交互项的 p 值),适合推断;论文更推荐

9.6.4 三方向副例异质性 ​

表 9.26 三方向副例异质性。

L4|L4|L4|L4

方向 & 异质性维度 & 分组变量 & 预期结论
【金】资本结构 & 企业规模(大/中/小) & size_group & 大企业融资渠道多元,杠杆率对治理更不敏感
【险】农业保险需求 & 城乡(城区/郊县/农村) & urban_rural & 农村农户风险厌恶更强,保险需求对补贴更敏感
【农】微型金融贷款可得性 & 区域(东部/中部/西部) & region & 西部金融抑制更强,关系型贷款效应更显著\

§9.7 中介效应与机制检验 ​

9.7.1 Baron-Kenny 三步法 ​

中介效应的经典检验框架由 Baron & Kenny(1986)提出,包含三步回归:

X -----------------------> Y          (第 1 步:总效应 c)
X -----------------------> M          (第 2 步:X 对中介变量的效应 a)
X ---------> M -----------> Y          (第 3 步:直接效应 c' + 中介效应 a×b)

表 9.27 Baron-Kenny 三步法。

L4|L4|L4|L4

步骤 & 回归方程 & 关注系数 & 含义
第 1 步 & Y = α0 + c·X + 控制变量 & c & X 对 Y 的总效应
第 2 步 & M = β0 + a·X + 控制变量 & a & X 对中介变量 M 的效应
第 3 步 & Y = γ0 + c’·X + b·M + 控制变量 & c’, b & c’ = 直接效应;b = M 对 Y 的效应\

中介效应 = a × b = c - c’

判定标准(逐步检验法):

  1. 第 1 步 c 显著 → X 确实影响 Y

  2. 第 2 步 a 显著 → X 确实影响 M

  3. 第 3 步 b 显著,且 c’ 的绝对值 < c 的绝对值 → 存在部分中介

  4. 若 c’ 不显著 → 完全中介(X 完全通过 M 影响 Y)

* ======================================================
* Baron-Kenny 三步法:governance -> npl_ratio -> roe
* 假说:公司治理(governance)通过降低不良贷款率(npl_ratio)提升盈利能力(roe)
* ======================================================

use "data/clean/bank_panel.dta", clear
xtset bank_id year

* Step 1: Y 对 X 回归(总效应 c)
xtreg roe governance size leverage roa cost_income i.year, fe cluster(bank_id)
est store step1
* 预期:governance 系数 c = 0.052***(SE = 0.018)

* Step 2: M 对 X 回归(效应 a)
xtreg npl_ratio governance size leverage roa cost_income i.year, fe cluster(bank_id)
est store step2
* 预期:governance 系数 a = -0.038***(SE = 0.012)
* 解读:公司治理改善 -> 不良贷款率下降

* Step 3: Y 对 X + M 回归(直接效应 c' + 中介效应 b)
xtreg roe governance npl_ratio size leverage roa cost_income i.year, fe cluster(bank_id)
est store step3
* 预期:
*   governance 系数 c' = 0.031**(SE = 0.015)—— 直接效应
*   npl_ratio 系数 b = -0.553***(SE = 0.142)
*   中介效应 = a × b = (-0.038) × (-0.553) = 0.021
*   c'/c = 0.031/0.052 = 59.6% —— 直接效应占总效应的比例
*   中介占比 = 0.021/0.052 = 40.4%

* 汇总输出三步骤表格
esttab step1 step2 step3, ///
    b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) ///
    keep(governance npl_ratio) ///
    mtitles("Step1: Y~X" "Step2: M~X" "Step3: Y~X+M") ///
    title("表 9-7  Baron-Kenny 三步法中介效应检验") ///
    label booktabs

9.7.2 Sobel 检验 ​

Baron-Kenny 逐步法有一个缺陷:它不直接检验“a × b 是否显著异于 0”。Sobel(1982)提出了中介效应的直接检验:

Sobel Z 统计量:Z = a·b / SE(a·b),其中 SE(a·b) = √(a²·SE_b² + b²·SE_a²)

判读:|Z| > 1.96 → 中介效应在 5% 水平显著。

局限:Sobel 检验假设 a·b 服从正态分布,但乘积分布通常偏态 → 检验力偏低 → 推荐用 Bootstrap 替代。

9.7.3 Bootstrap 置信区间(推荐方法) ​

Bootstrap 不依赖正态性假设,直接通过重复抽样构造 a·b 的置信区间:

* ======================================================
* sgmediation:一键中介效应(Sobel + Bootstrap)
* 需安装:ssc install sgmediation
* ======================================================

* 方法一:sgmediation(经典三步 + Sobel 检验)
sgmediation roe, mv(npl_ratio) iv(governance) cv(size leverage)
* 输出解读:
*   --------------------------------------------------
*   Baron-Kenny 三步法结果
*   --------------------------------------------------
*   Step 1 (Y ~ X):     governance -> roe
*     c  = 0.0523 (p < 0.001)      总效应显著 ✓
*
*   Step 2 (M ~ X):     governance -> npl_ratio
*     a  = -0.0381 (p < 0.001)     X 对 M 效应显著 ✓
*
*   Step 3 (Y ~ X + M): governance + npl_ratio -> roe
*     b  = -0.5532 (p < 0.001)     M 对 Y 效应显著 ✓
*     c' = 0.0312 (p = 0.038)      直接效应仍显著 -> 部分中介
*
*   Sobel 检验:
*     Z = a*b / SE(a*b) = 0.021 / 0.008 = 2.63
*     p = 0.009 -> 中介效应在 1% 水平显著
*
*   中介效应占比 = a*b / c = 0.021 / 0.052 = 40.4%
*   --------------------------------------------------

* 方法二:Bootstrap 中介效应(更推荐,不依赖正态假设)
capture program drop my_mediation
program define my_mediation, rclass
    syntax [anything]
    xtreg npl_ratio governance size leverage i.year, fe cluster(bank_id)
    local a = _b[governance]
    xtreg roe governance npl_ratio size leverage i.year, fe cluster(bank_id)
    local b = _b[npl_ratio]
    return scalar ind_eff = `a' * `b'
end

bootstrap r(ind_eff), reps(1000) seed(42) cluster(bank_id): my_mediation
estat bootstrap, percentile bc

结果解读模板(写入论文):

9.7.4 路径分析与中介效应的术语对照 ​

“多变量 GLM 中,一个方程的因变量是另一个方程的自变量”——这正是路径分析(Path Analysis)的定义,也是中介效应的本质。

对应关系:

表 9.28 路径分析与中介效应的术语对照。

L3|L3|L3

路径分析概念 & 中介效应术语 & Stata 实现
外生变量 & X(自变量) & governance
内生变量(中间) & M(中介变量) & npl_ratio
最终内生变量 & Y(因变量) & roe
直接路径系数 & c’(直接效应) & 第 3 步 X 的系数
间接路径系数 & a × b(间接效应) & 两步系数乘积
总效应 & c = c’ + a·b & 第 1 步 X 的系数\

中介效应是路径分析的最简形态(单条间接路径)。更复杂的多路径模型(如 SEM)将在高级课程中学习。

9.7.5 中介效应 vs 调节效应辨析 ​

表 9.29 中介效应 vs 调节效应辨析。

L3|L3|L3

维度 & 中介效应(Mediation) & 调节效应(Moderation)
回答的问题 & X 通过什么渠道影响 Y? & X 对 Y 的影响在什么条件下更强/更弱?
变量角色 & M 是 X→Y 链条上的中间环节 & W 改变 X→Y 关系的强度/方向
因果图 & X → M → Y & X → Y,W 调节箭头粗细
检验方法 & Baron-Kenny / Bootstrap & 交乘项 X×W 是否显著(§9.6.3)
Stata 命令 & sgmediation & reghdfe y c.x##c.w
本章对应 & §9.7 & §9.6.3 异质性分析\

常见混淆:异质性分析(§9.6.3)本质上就是调节效应检验——“治理效应在国有银行和非国有银行之间不同”= “银行类型调节了治理→绩效的关系”。

§9.8 ABM 仿真实验 ​

9.8.1 为什么需要仿真? ​

回归分析(§9.1-§9.7)的核心能力是:从已经发生的数据中,利用自然实验或统计控制来识别因果关系。但有些研究问题是回归无法回答的:

表 9.30 为什么需要仿真?。

L3|L3|L3

局限 & 例子 & ABM 的解决方案
无法做 RCT & 农业保险补贴率不能随机分配给不同省份 & 在计算机中模拟“如果补贴率是 60%/70%/80%/90%”的反事实
数据不存在 & 新政策尚未实施,没有历史数据 & 基于行为规则模拟政策实施后的可能结果
系统复杂性 & 500 个农户相互影响(邻里效应)、多主体博弈 & 让每个 Agent 遵循决策规则,观察宏观涌现
非线性动态 & 参保率随时间的路径依赖(先亏后保 vs 一直不保) & 离散时间步逐期模拟,观察动态轨迹\

定位:ABM 不是回归的替代品。最佳实践是“回归 + 仿真”双轮驱动——回归验证历史因果,仿真预测政策效果。

9.8.2 ODD 协议:模型描述的国际标准 ​

ABM 模型如果没有标准化的描述文档,他人无法复现、审稿人无法评审。ODD 协议(Grimm et al., 2006)是国际公认的 ABM 报告标准:

表 9.31 ODD 协议:模型描述的国际标准。

L3|L3|L3

ODD 组件 & 含义 & 四川水稻保险 ABM 对应
Overview & 概述:目的、主体类型、空间结构、时间尺度 & 评估补贴率政策效果;4 类主体(农户/保险公司/银行/政府);小世界网络;步长=1天
Design concepts & 设计理念:涌现、适应性、目标、学习、随机性 & 参保率涌现;农户根据前景理论适应决策;多随机种子
Details & 细节:状态变量、过程、调度顺序 & config.yaml 全部参数 + 年度周期(投保→生产→灾害→收获→理赔)\

写论文的启示:如果你的专硕论文选择“产品设计”范式(附录 F.3),其中包含仿真模块,那么 ODD 协议就是“方法”一节必须遵循的报告框架。

9.8.3 四川水稻保险 ABM 跟做 ​

项目路径(绝对路径,请复制到你自己的研究文件夹后再运行):

/Users/xiaoshiishun/微云同步助手(275531137)/当前工作/课件/风险管理与保险研究生课程2026年讲义更新/sichuan_rice_insurance_abm/

项目结构:

sichuan_rice_insurance_abm/
+-- run.py                      # 启动脚本(python run.py --scenario baseline)
+-- config.yaml                 # 全部参数配置(YAML 格式)
+-- ODD协议.md                  # ODD 标准描述文档
+-- model/rice_insurance_model.py   # 主模型类
+-- agents/rice_farmer_agent.py     # 农户主体(核心决策逻辑)
+-- agents/insurer_agent.py         # 保险公司
+-- agents/bank_agent.py            # 银行(保险+信贷联动)
+-- agents/government_agent.py      # 政府(补贴政策)
+-- results/                        # 运行输出

核心参数一览(来自 config.yaml):

表 9.32 四川水稻保险 ABM 跟做。

L4|L4|L4|L4

参数类别 & 关键参数 & 取值 & 数据来源
模型规模 & 农户数量 & 500 & 代表四川 2800 万亩水稻种植户样本
网络结构 & 小世界网络 k=8, p=0.1 & — & 模拟农村熟人社会
风险偏好 & CRRA 风险厌恶系数 & N(1.2, 0.4) & 文献估计
行为参数 & 损失厌恶系数 λ & N(2.8, 0.6) & 蔡天鸣(2024)中国农户实验
保险合约 & 保额 1100 元/亩,费率 4.5% & 保费 49.5 元/亩 & 四川水稻完全成本保险条款
财政补贴 & 总补贴率 75%(中央45%+省20%+市县10%) & 农户自缴 25% ≈ 12.4 元/亩 & 四川省农业农村厅
灾害参数 & 洪涝 3%/年,干旱 2%/年,病虫害 5%/年 & — & 国家统计局四川调查总队\

跟做步骤:

# 步骤 1:复制项目到你的研究文件夹
cp -r "/Users/xiaoshiishun/微云同步助手(275531137)/当前工作/课件/风险管理与保险研究生课程2026年讲义更新/sichuan_rice_insurance_abm/" ~/research/my_abm/

# 步骤 2:安装依赖
cd ~/research/my_abm
pip install -r requirements.txt

# 步骤 3:运行基准情景(补贴率 75%)
python run.py --scenario baseline
# 观察输出:参保率、财政支出、赔付率

# 步骤 4:运行补贴率扫描实验(50% -> 90%,步长 5%)
python run.py --scenario subsidy_sweep
# 输出四指标曲线:补贴率 -> 参保率 -> 财政效率 -> 赔付率

subsidy_sweep 参数扫描的四个输出指标:

表 9.33 指标 / 含义 / 政策关注点速查表。

L3|L3|L3

指标 & 含义 & 政策关注点
参保率 & 投保农户占比 & 政策目标:≥85%
财政支出 & 政府补贴总额 & 预算约束:≤8000万元
财政效率 & 每万元财政支出带动的参保率提升 & 边际效益递减点在哪?
赔付率 & 保险公司理赔/保费收入 & 可持续性:60%-80% 为健康区间\

论文写法:跑完 subsidy_sweep 后,画四指标对补贴率的折线图,找到“参保率≥85% 且财政效率最大”的拐点 → 这就是你的政策建议。

9.8.4 ABM 诚信边界 ​

+-----------------------------------------------------------------------+
|  [!] ABM 仿真的三条诚信红线                                             |
|                                                                       |
|  1. 仿真结果 ≠ 现实                                                    |
|     · ABM 输出是"在假设条件下的可能结果",不是预测                        |
|     · 论文中必须写"本模型结果依赖于以下假设:..."                         |
|                                                                       |
|  2. 参数校准与来源必须披露                                              |
|     · 每一个参数都要注明数据来源(文献/统计年鉴/调研)                     |
|     · 禁止"拍脑袋"设定关键行为参数(如风险厌恶系数)                      |
|     · config.yaml 中的注释就是你的"参数审计轨迹"                        |
|                                                                       |
|  3. 禁止调参凑结论                                                      |
|     · 不得反复修改参数直到仿真结果"符合预期"                              |
|     · 正确做法:先确定参数(有来源)-> 跑模型 -> 如实报告结果                |
|     · 如果结果与预期不符 -> 讨论为什么,而不是改参数                        |
|     · 敏感性分析(±20% 扰动)是合法的稳健性检验                          |
|     · 多随机种子(seed=42,123,456,789,999)报告均值和标准差               |
+-----------------------------------------------------------------------+

S9.4 延伸:AI 可以帮你写 Python 仿真代码、解释 ODD 协议、调试报错;但 AI 不能帮你编造参数值或伪造仿真输出。所有参数必须有可追溯的来源。

AI 辅助研究栏 · 第 9 章 ​

AI 在实证分析中的合法应用 ​

① 贴回归输出让 AI 诊断(推荐提示词模板) ​
我跑了一个面板回归(reghdfe),输出如下:

[粘贴 Stata 输出]

请帮我诊断:
1. 是否存在异方差疑虑?(看 Breusch-Pagan 或 White 检验 p 值)
2. 是否存在多重共线性?(看 VIF 值)
3. 是否有内生性风险?(核心解释变量是否可能与误差项相关)
4. 我的聚类标准误选择是否合理?

请不要帮我编造任何数字,只基于我贴的输出进行分析。
② stata-mcp 六步法 AI 协作要点 ​

表 9.34 AI 在实证分析中的合法应用。

L3|L3|L3

六步法步骤 & AI 可以做什么 & AI 不能做什么
Step 1 数据导入 & 帮你写 import excel / use 代码 & 帮你编造数据
Step 2 描述统计 & 生成 summarize / tabstat 代码 & 编造描述统计数值
Step 3 基准回归 & 推荐模型设定、写回归命令 & 生成回归系数
Step 4 内生性 & 帮你想 IV 候选、写 ivregress 代码 & 编造第一阶段 F 值
Step 5 稳健性 & 生成多组检验代码框架 & 选择性报告(AI 不知道哪些“好看”)
Step 6 输出 & 写 esttab / putdocx 格式化命令 & 伪造表格中的数字\

③ AI 能做 / 不能做对照表 ​

表 9.35 OliveGreen ding51。 AI 能做 / Red ding55 AI

L2|L2

✅ AI 能做 & ❌ AI 绝对不能做
根据你的描述生成 Stata 代码 & 生成回归系数、标准误、p 值、R²
解释回归输出中各统计量的含义 & 编造“看起来合理”的数字填入论文
诊断异方差/共线性/内生性的可能原因 & 替你判断“该不该剔除这个样本”
推荐识别策略(IV/DID/PSM/RDD) & 保证推荐的策略适用于你的数据
帮你写 esttab / coefplot 美化代码 & 修改你的实证结果使其“更好看”
翻译统计术语为日常语言 & 替代你对理论的理解\


AI 诚信栏 · 第 9 章 ​

S9.1 不 p-hacking ​

+-----------------------------------------------------+
|  * 诚信检查点 S9.1                                    |
|                                                       |
|  核心原则:                                            |
|  模型设定必须基于理论,不是基于"哪种设定最显著"。       |
|  铁律:"数据是用来验证模型的,而不是用来设定模型的" |
|                                                       |
|  具体要求:                                            |
|  □ 不得"换三个控制变量组合终于显著了"只报显著那个      |
|  □ 不得事后剔除"异常值"以凑显著                        |
|    (剔除标准必须事前确定,如 winsor2 在回归前完成)   |
|  □ 不得尝试多个因变量只报告显著的那个                  |
|  □ 不得隐藏不显著的尝试——规格曲线就是你的"自证清白"   |
|                                                       |
|  自检方法:                                            |
|  画一张规格曲线(§9.6.2),展示所有合理设定下核心      |
|  系数的分布。如果曲线在 0 两侧频繁穿越,说明你的       |
|  结论不稳健——此时诚实比显著更重要。                    |
|                                                       |
|  反面教材:                                            |
|  · "我试了 20 种控制变量组合,第 17 种终于 p<0.05"    |
|  · 论文报告 N=387,实际原始数据 N=500——中间悄悄       |
|    删了 113 个"异常值"但没说明标准                     |
|  · 先跑 ROE 不显著,换 ROA 显著了,只报 ROA 结果      |
+-----------------------------------------------------+

S9.2 稳健性检验如实报告 ​

+-----------------------------------------------------+
|  * 诚信检查点 S9.2                                    |
|                                                       |
|  核心原则:                                            |
|  稳健性检验是给读者提供完整信息,不是给自己找退路。    |
|  "失败的稳健性检验"同样必须如实报告。                  |
|                                                       |
|  具体要求:                                            |
|  □ 三组检验全做:主检验 + 替换变量 + 子样本            |
|  □ 所有结果写入论文表格(通常 4-6 列)                 |
|  □ 如果某组不显著,写"在 XX 条件下不再稳健"并讨论     |
|  □ 不得把不显著的稳健性检验藏在附录/脚注中            |
|  □ 表述格式统一:                                      |
|    "在替换 X 变量后,核心结论保持/不再稳健"           |
|                                                       |
|  自检方法:                                            |
|  检查你的论文稳健性表格是否有"全是星号"的可疑现象。   |
|  现实中,稳健性检验有部分不显著是正常的。              |
|                                                       |
|  反面教材:                                            |
|  · 跑了 10 种稳健性检验,只把显著的 4 种放进论文      |
|  · 稳健性表格所有列都 p<0.01——高度可疑                |
|  · "替换因变量后不显著"但论文中只字不提                |
+-----------------------------------------------------+

S9.3 可复现三件套 ​

+-----------------------------------------------------+
|  * 诚信检查点 S9.3                                    |
|                                                       |
|  核心原则:                                            |
|  你的实证分析必须"一键可复现"——同学拿到你的文件夹,   |
|  运行 master.do,能得到和你论文中一模一样的表格。      |
|                                                       |
|  具体要求:                                            |
|  □ do 文件:从 use "data/raw/xxx.dta" 开始            |
|    · data/raw/ 只读存档(原始数据,绝不修改)          |
|    · do 文件生成 data/clean/(清洗后数据)             |
|    · 回归 → 表格 → 图全部在 do 文件中完成             |
|  □ data 文件夹结构:                                   |
|    · data/raw/     → 原始数据(只读)                 |
|    · data/clean/   → 清洗后数据(do 生成)            |
|    · data/derived/ → 中间变量(do 生成)              |
|  □ log 文件:                                          |
|    · 每次运行自动生成带时间戳的 log                   |
|    · log 中包含所有命令 + 输出 + 运行环境信息          |
|                                                       |
|  自检方法:                                            |
|  □ 把 master.do 发给同学从零跑一遍                    |
|  □ 对比 log 中的数字与论文表格是否完全一致            |
|  □ 确认 data/raw/ 从未被修改(对比 MD5 校验码)       |
|                                                       |
|  反面教材:                                            |
|  · "这个表格是我三个月前跑的,现在找不到代码了"       |
|  · data/raw/ 被直接修改过,无法追溯原始数据            |
|  · data/raw/ 被直接修改过,无法追溯原始数据            |
|  · log 文件中的 N=450 但论文写 N=453                  |
+-----------------------------------------------------+

S9.4 AI 辅助计量不编造系数 ​

+-----------------------------------------------------+
|  * 诚信检查点 S9.4                                    |
|                                                       |
|  核心原则:                                            |
|  AI 是你的"编程助手"和"翻译官",不是"数据生成器"。   |
|  论文中出现的每一个数字,都必须来自你自己的 Stata 运行。|
|                                                       |
|  具体要求:                                            |
|  □ AI 可以做:写代码 / 解释输出 / 诊断问题 / 推荐方法 |
|  □ AI 绝对不能做:                                     |
|    · 生成回归系数(如"b=0.045, se=0.012, p<0.01")  |
|    · 编造 F 统计量、R²、Hausman 检验 p 值             |
|    · 虚构"看起来合理"的稳健性检验结果                 |
|  □ 检测红线:论文中任何一个数字,导师有权要求你        |
|    当场打开 Stata 复现                                  |
|                                                       |
|  自检方法:                                            |
|  □ 打开你的 log 文件,逐一核对论文表格中的数字         |
|  □ 确认每个系数都能在 log 中找到对应输出               |
|  □ 如果你在 ChatGPT/AI 对话中看到"建议系数为..."     |
|    立即警惕——这不是你的数据                           |
|                                                       |
|  反面教材:                                            |
|  · 问 AI "帮我写一段实证结果",AI 编造了系数,        |
|    你直接复制进论文                                    |
|  · 导师要求当场跑回归,你说"我回去跑给你看"           |
|  · 导师要求当场跑回归,你说"我回去跑给你看"           |
|  · log 文件和论文表格数字不一致(说明表格是手打的)    |
+-----------------------------------------------------+

本章产出物 ​

表 9.36 本章产出物。

L4|L4|L4|L4

序号 & 产出物 & 文件名建议 & 说明
1 & 实证论文草稿 & my_paper_v1.docx & ≥8000 字,含完整实证章节
2 & 基准回归表 & & OLS/FE/RE 三列对照
3 & DID 回归表 & & 双重差分主表 + 事件研究图
4 & 中介效应表 & & Baron-Kenny 三步 + Bootstrap CI
5 & 系数图 & & 核心变量系数及 95% CI
6 & AI 使用声明 & ai_disclosure_v1.md & 开题版(说明 AI 在哪些环节参与)
7 & (选修)ABM 报告 & abm_sweep_report.md & subsidy_sweep 四指标结果与政策建议\

提交要求:产出物 1-6 为必交项,产出物 7 为选修加分项。所有文件遵循 S9.3 可复现三件套标准(do + data + log 齐备)。


下一章预告:第 9 章走的是“回归路线”——用统计模型从数据中识别因果。但并非所有研究问题都适合回归。第 10 章将进入“案例研究路线”:当你的问题是 How 型(“某政策是如何落地的?”)或 Why 型(“某银行为何失败?”)时,案例研究能给你回归给不了的过程性洞察。两条路线不是对立的——好的专硕论文常常是“案例 + 数据”混合设计。


English Edition ​

Chapter 9 · Inference and Empirical Strategy ​


Chapter Overview ​

Learning Objectives ​

After completing this chapter, you should be able to:

  1. State how the GLM (general linear model) subsumes t tests, ANOVA, and regression—the three are not “three methods” but different faces of one coin

  2. Select the identification strategy that best matches your research hypothesis (OLS / FE / IV / DID / PSM / RDD)

  3. Complete the “six-step” empirical workflow driven by stata-mcp (description → baseline → endogeneity → robustness → mechanism → heterogeneity)

  4. Explain which of Chapter 4’s seven validity threats each identification strategy resolves

  5. Independently write a reproducible empirical do-file (from use data/raw/ to esttab using ...)

Core Idea ​

One sentence is the soul of this chapter. In Chapter 8 you learned to give data a “physical examination” (descriptive statistics); this chapter does the opposite: first fix the model on theoretical grounds, then let the data test it. If you keep swapping variables and samples until p < 0.05—that is p-hacking, the red line of this chapter’s integrity checkpoint S9.1.

Section Structure ​

Table 9.1 Section structure.

L3|L3|L3

Section & Title & Core methods
9.0 & The GLM umbrella & t test / ANOVA / regression all belong to GLM; two-group comparison; 2×2 factorial design
9.1 & OLS baseline regression & reg / vce(robust) / vif / estat hettest / estat ovtest
9.2 & Panel data: FE and RE & xtset / reghdfe / hausman / BP-LM
9.3 & Instrumental variables (IV/2SLS) & ivregress 2sls / estat firststage / exclusion
9.4 & Difference-in-differences (DID) & did_multiplegt / eventstudyinteract / parallel trends
9.5 & PSM and RDD & psmatch2 / teffects psmatch / rdrobust
9.6 & Robustness and heterogeneity & alternative variables / subsamples / specification curves
9.7 & Mediation and mechanism tests & sgmediation (Sobel + Bootstrap)
9.8 & ABM simulation (elective) & ODD protocol / Sichuan rice-insurance ABM
Total & &\


[Takeaway] Where this chapter sits in the handbook

  • Building on Chapter 8: Chapter 8 taught you to “examine the data thoroughly so the regression can run with confidence”—descriptive statistics, missing-value handling, winsorizing, variable transformations. This chapter builds models directly on that “clean data.”

  • Echoing Chapter 4: every identification strategy (IV / DID / PSM / RDD / FE) addresses one or more of Chapter 4’s seven validity threats. When writing your paper you must say clearly: “I use DID because I need to address selection bias plus history effects.”

  • Contrast with Chapter 10: this chapter takes the “regression route” (What-type questions: does X causally affect Y? by how much?); Chapter 10 takes the “case route” (How-type questions: how did this process unfold?). The two routes were foreshadowed in §4.5’s “three-way strategy selection.”

  • Main dataset: bank_panel.dta (100 listed banks × 5 years), with variables roe (dependent variable), size, leverage, governance, board_size, bank_id, year. Three side examples: 【Finance】 determinants of capital structure / 【Insurance】 determinants of agricultural-insurance demand / 【Agriculture】 microfinance loan access.

§9.0 The GLM Umbrella ​

📐 结构图示(书版示意图的文字要点)

  1. tikzpicture
  2. ->,thick,NavyBlue
  3. t test
  4. e.g.
  5. ANOVA
  6. OLS regression
  7. MSB
  8. MSW

Figure 9.1 The GLM umbrella—t test, ANOVA, and regression are not three methods but three branches of one tree, cut by the type of X.


9.0.1 The GLM Family: t Test / ANOVA / Regression Share One Root ​

The general form of the GLM is y=β0+β1x1+⋯+βnxn+ε, where each xi may be continuous or a 0/1 dummy. Branching by the type of xi:

Table 9.2 The GLM family: t test / ANOVA / regression share one root.

L3|L3|L3

Predictor type & Corresponding method & Equivalent statement
One dummy variable (comparing two groups) & ANOVA = t test & the t test on the group coefficient in reg y i.group
Dummy + covariates & ANCOVA & ANOVA with control variables added
Several continuous predictors & Multiple regression & the OLS you already know
Several outcome variables & Multivariate regression / MANOVA & a system of equations
The dependent variable of one equation is a regressor of another & Structural equation modeling (SEM) & path analysis\

One-sentence summary: the GLM is a “super-framework”; the t test and ANOVA are merely its aliases under particular variable types.


9.0.2 Two-Group Comparison = The Simplest Regression ​

The key identity: when the predictor is a 0/1 dummy, β1 in reg y i.group equals exactly the two-group mean difference of an independent-samples t test, and the regression’s t statistic equals the t test’s t value. The full derivation appears in §9.1 (with the covariate extension).


9.0.3 The 2×2 Factorial Design and Interaction Terms ​

Two-factor GLM: y=β0+β1x1+β2x2+β3x1x2+ε, where β3 is the interaction effect. Core warning: when β3 is significant, β1 and β2 cannot be interpreted separately—this is precisely the logic underlying the DID estimator β3(Treati×Postt) in §9.4. The full DID derivation appears in §9.4.


9.0.4 The Theory-First Principle of Model Specification ​

“Model specification should rest on theoretical thinking about the phenomenon under study, not on which model best fits the observed data. Data are for testing models, not for specifying them.”—this is the root justification for this chapter’s integrity checkpoint S9.1, no p-hacking.

Table 9.3 The theory-first principle of model specification.

L2|L2

Theory-first (correct practice) & Data-driven (red-line behavior)
Fix the dependent variable, core regressor, and controls from the literature and theory first & Throw in every variable and keep whichever is significant
Fix the sample scope first (e.g., “A-share listed banks 2019–2023”) & Drop “outliers” ex post until the result turns significant
Fix one main model, then run robustness checks & Run 20 specifications and report only the significant one
Show the distribution of results across all reasonable specifications with a specification curve & Conceal the insignificant specifications\

Practical advice: before running any regression, write your theoretical model into the file header as comments:

* ==========================================================
* Theoretical model (fixed BEFORE writing code; no ex post edits)
* ==========================================================
* Hypothesis H1: corporate governance (governance) raises bank ROE
* Dependent variable: roe
* Core regressor: governance
* Controls: size, leverage, board_size
* Theoretical basis: agency theory (Jensen & Meckling, 1976)
* Sample: A-share listed banks 2019-2023 (100 banks x 5 years = 500 obs)
* Identification: OLS baseline + FE robustness (time-invariant omitted vars)
* ==========================================================

9.0.5 Stata Demo: Equivalence of t Test / ANOVA / Regression ​

The following uses the main dataset bank_panel.dta to show how the three commands deliver the same conclusion:

* -- Load data --
use data/clean/bank_panel.dta, clear

* Create a binary grouping variable: high governance = above median
qui sum governance, detail
gen hi_gov = (governance > r(p50))
label var hi_gov "high-governance group (1) vs low (0)"

* Method 1: independent-samples t test
ttest roe, by(hi_gov)

* Method 2: one-way ANOVA
anova roe i.hi_gov

* Method 3: OLS regression (equivalent to the t test)
reg roe i.hi_gov

* Extension: 2x2 factorial design (structurally identical to DID)
gen post = (year >= 2021)
reg roe i.hi_gov##i.post   // 1.hi_gov#1.post is the DID estimator

Equivalence verification checklist:

Table 9.4 Stata demo: equivalence of t test / ANOVA / regression.

L4|L4|L4|L4

Comparison dimension & ttest & anova & reg y i.group
Effect size & mean difference diff & — & coefficient β1
Test statistic & t & F = t² & t
p value & ✅ (identical) & ✅ (identical) & ✅ (identical)
Confidence interval & ✅ & — & ✅
Extensibility & two groups only & multiple groups & controls and interactions allowed\

Conclusion: mastering reg means mastering both the t test and ANOVA. The GLM framework lets you handle everything from simple comparisons to complex causal inference with one set of commands.


9.0.6 GLM Thinking in the Three Side Examples ​

Table 9.5 GLM thinking in the three side examples.

L4|L4|L4|L4

Field & Research question & GLM specification & Meaning of the interaction
【Finance】 capital structure & Does corporate governance affect leverage? & reg leverage i.hi_gov size roe & governance×size: is the governance effect different for large firms?
【Insurance】 ag-insurance demand & Does risk aversion affect insurance take-up? & logit insure i.risk_averse income age & risk aversion×income: stronger aversion effect among high-income farmers?
【Agriculture】 microfinance & Does joint liability raise repayment rates? & & joint liability×rural: stronger effect in rural areas?\

[Key] Remember: whatever your field—finance, insurance, or rural economics—the underlying statistical logic is the GLM. Differences lie only in the dependent-variable type (continuous → OLS; binary → Logit/Probit), the data structure (cross-section / panel / time series), and the identification strategy (§9.1–§9.5).

Method-Selection Decision Tree (Quick Reference) ​

The Decision Tree ​

Is your research question causal inference?
+-- No -> descriptive statistics / correlation (Chapter 8)
+-- Yes -> do you have random assignment (an experiment)?
    +-- Yes -> true-experiment analysis (t test/ANOVA -> §9.0 GLM)
    +-- No -> observational data (non-experimental / retrospective)
        +-- An exogenous shock / policy change?
        |   +-- Yes + pre/post two periods -> DID (§9.4)
        |   +-- Yes + continuous treatment -> RDD (§9.5)
        +-- A valid instrument?
        |   +-- Yes -> IV/2SLS (§9.3)
        |   +-- No -> a matched control group?
        |       +-- Yes -> PSM (§9.5)
        |       +-- No -> panel data?
        |           +-- Yes -> FE/RE (§9.2)
        |           +-- No -> OLS with ample controls (§9.1)
        +-- None of the above -> say honestly "correlated but not causal"

How to Use the Tree ​

The tree is used in three steps:

Step 1: confirm your question type. If you ask “are X and Y related” (correlation), Chapter 8’s descriptive statistics suffice. If you ask “does X cause Y” (causation), you proceed.

Step 2: inventory your “identification resources.” Check in order: is there an exogenous policy shock? A usable instrument? A matchable control group? Is the data panel or cross-sectional?—you should start thinking about these when downloading data in Chapter 5 and designing the questionnaire in Chapter 6.

Step 3: choose the “cleanest” strategy. Prefer the strategy with the fewest identifying assumptions (DID needs parallel trends; IV needs exclusion; PSM needs observable controls; FE needs only “omitted variables are time-invariant”). If a strategy’s assumptions fail in your setting, fall back to the next—but discuss the limitation honestly in the paper.


The Three-Layer Structure ​

+------------------------------------------------------+
|  Layer 1: data structure sets the method's boundary  |
|                                                      |
|  Cross-section --> OLS / PSM / RDD / IV              |
|  Panel         --> FE / RE / DID / IV                |
|  Time series   --> ARIMA / VAR (not here; App. B)    |
|                                                      |
+------------------------------------------------------+
|                                                      |
|  Layer 2: the research question sets identification  |
|                                                      |
|  "Are X and Y related"  --> OLS / FE                 |
|  "Does X cause Y"       --> causal identification    |
|    - exogenous policy shock? --> DID                 |
|    - valid instrument?       --> IV/2SLS             |
|    - cutoff / threshold?     --> RDD                 |
|    - selection on observables? --> PSM               |
|                                                      |
+------------------------------------------------------+
|  Layer 3: diagnosis and repair                       |
|                                                      |
|  Heteroskedasticity --> robust SE (vce(robust))      |
|  Collinearity       --> drop / merge variables       |
|  Specification error--> add polynomials/interactions |
|  Endogeneity        --> IV / FE / DID                |
|                                                      |
+------------------------------------------------------+
|                                                      |
|  [Note] Mechanism analysis requires a significant,   |
|  robust main effect first                            |
+------------------------------------------------------+

§9.1 OLS Baseline Regression (Part 1): Assumptions and Diagnostics ​

Core idea: OLS is not merely a command; it is a contract—you assume the data satisfy five conditions, and only then can Stata guarantee unbiased and efficient coefficients. Diagnose first, trust later.

9.1.1 The Five Classic OLS Assumptions (Gauss-Markov Conditions) ​

In Chapter 1 you already ran reg roe size leverage governance board_size, but then we only cared whether “the pipeline runs.” Now the serious question: on what grounds do we trust this set of coefficients?

The answer: on the grounds that all five assumptions hold.

Table 9.6 The five classic OLS assumptions (Gauss-Markov conditions).

L5|L5|L5|L5|L5

# & Assumption & Formal statement & Intuition & Consequence of violation
A1 & Linearity in parameters & y=β0+β1x1+⋯+βkxk+ε & the model is linear in β (x may be transformed nonlinearly) & wrong interpretation of coefficients
A2 & Random sampling & the sample is drawn i.i.d. from the population & observations are independent and identically distributed & standard errors invalid; inference unreliable
A3 & No perfect collinearity & no exact linear relationship among regressors & no x may be a perfect linear combination of the others & Stata silently drops variables
A4 & Zero conditional mean & E(ε∣x1,…,xk)=0 & the error is uncorrelated with the regressors (no endogeneity) & coefficients biased and inconsistent (the worst)
A5 & Homoskedasticity & Var(ε∣x)=σ2 (constant) & the disturbance’s spread is the same at every x & coefficients still unbiased, but SEs biased → inference fails\

[Takeaway] Key principle—“data are for testing models, not for specifying them.” The five assumptions are your theoretical commitments when specifying the model; the diagnostic tests are the data-side evidence for verifying those commitments.

Why is A4 the worst? Because once E(ε∣x)≠0 (omitted variables, reverse causality, measurement error), the OLS coefficients are wrong and no larger sample can save them—that is what “inconsistent” means. §9.3’s IV and §9.2’s FE are precisely the two scalpels aimed at A4 violations.

9.1.2 Diagnosing Heteroskedasticity ​

Heteroskedasticity = A5 violated. Intuitively, large banks’ ROE may fluctuate more than small banks’—creating “different variances at different x values.”

* -- Heteroskedasticity diagnosis --
* Prerequisite: run reg first (diagnostics must follow reg immediately)
use "data/clean/bank_panel.dta", clear
reg roe size leverage governance board_size

* Method 1: Breusch-Pagan test (BP test)
* H0: homoskedasticity (residual variance unrelated to regressors)
estat hettest
* Sample output:
*   chi2(4) = 15.23
*   Prob > chi2 = 0.0043
* Read: p = 0.0043 < 0.05 -> reject H0 -> heteroskedasticity present

* Method 2: White test (more general, allows cross terms)
estat imtest, white
* Sample output:
*                  |       chi2     df      Pr > chi2
*   --------------+-----------------------------------
*   Fit |           23.45     14       0.0498
*   Squares |       18.67     14       0.1735
*   Skewness |       2.34      4       0.6734
*   Kurtosis |       3.12      4       0.5378
* Read: Fit row p = 0.0498 < 0.05 -> evidence of heteroskedasticity

* -- Fix: re-run with robust standard errors --
reg roe size leverage governance board_size, vce(robust)
* vce(robust) = Huber-White robust standard errors
* coefficients unchanged; SEs corrected -> t and p values may change

Decision rules:

Table 9.7 Diagnosing heteroskedasticity.

L3|L3|L3

Test result & Conclusion & Next step
both BP and White p > 0.10 & no evidence of heteroskedasticity & report classic standard errors
either p < 0.05 & heteroskedasticity present & must re-run with vce(robust) (see §9.1 part 2)
0.05 < p < 0.10 & borderline & be conservative: use robust SEs and note it in a footnote\

9.1.3 Diagnosing Multicollinearity ​

Multicollinearity = regressors highly correlated with one another (e.g., size and leverage often move together among large banks). It does not bias coefficients, but inflates standard errors → significance falls → “variables that should be significant turn insignificant.”

* -- Multicollinearity diagnosis --
* Must be run after reg
estat vif
* Reading the output:
*   Variable |      VIF        1/VIF
*   ---------+----------------------
*   size     |     X.XX        0.XXXX
*   leverage |     X.XX        0.XXXX
*   ...
*   Mean VIF |     X.XX
*
* Rules of thumb:
*   VIF > 10  -> severe collinearity for that variable, beware
*   VIF > 5   -> moderate collinearity, watch but don't panic
*   VIF < 5   -> safe
*   Mean VIF > 3 -> model-wide collinearity somewhat high

* -- Simple correlation matrix as auxiliary evidence --
correlate size leverage governance board_size
* whenever |r| > 0.8 between two variables, their VIF is usually > 5

Handling strategies (in priority order):

  1. Do nothing: if the core variable’s sign and significance are unchanged and collinearity only silences some “nice-to-have” controls, report as is

  2. Drop redundant variables: remove the variable with the highest VIF that is least necessary theoretically

  3. Merge variables: if multiple indicators measure one construct, combine them via factor scores or averages (echoing §5.4)

  4. Enlarge the sample: collinearity is a symptom of “insufficient information”; more data helps discriminate

9.1.4 Specification Error (RESET Test) ​

The RESET test (Regression Equation Specification Error Test) answers a fundamental question: is your linear specification correct? Are important nonlinear or interaction terms missing?

* -- RESET test (Ramsey 1969) --
estat ovtest
* H0: the model is correctly specified (no omitted higher-order terms)
* H1: specification error exists
*
* Reading the output:
*   F(3, 495) = X.XX
*   Prob > F =    0.XXXX
* Decision:
*   p < 0.05 -> reject H0 -> specification error
*   p > 0.10 -> fail to reject H0 -> specification acceptable

* -- Fixes (use when RESET is significant) --
* Fix 1: add a squared term of the key variable
gen size_sq = size^2
reg roe size size_sq leverage governance board_size
estat ovtest   /* retest: has the p value improved? */

* Fix 2: add a plausible interaction (theory-driven)
gen gov_x_lev = governance * leverage
reg roe size leverage governance board_size gov_x_lev
estat ovtest   /* retest */

* Fix 3: take logs of the dependent variable (if economically meaningful)
gen ln_roe = ln(roe) if roe > 0
reg ln_roe size leverage governance board_size

9.1.5 The Complete Four-Diagnostic Workflow ​

Integrate the three diagnostics above into one standard routine—run it after every baseline regression from now on:

* ======================================================
* §9.1 complete diagnostic workflow template (bank_panel.dta)
* ======================================================
use "data/clean/bank_panel.dta", clear

* Step 1: baseline regression
reg roe size leverage governance board_size
estimates store m1_baseline

* Step 2: heteroskedasticity diagnostics
estat hettest          /* BP test */
estat imtest, white    /* White test */
* -> record both p values and judge whether heteroskedasticity exists

* Step 3: multicollinearity diagnosis
estat vif
* -> record Mean VIF; check whether < 3 (safe)

* Step 4: specification test
estat ovtest           /* RESET test */
* -> record the p value and judge whether higher-order terms are needed

* Step 5: fix---re-run with robust standard errors
reg roe size leverage governance board_size, vce(robust)
estimates store m2_robust

* Step 6: export a comparison table
esttab m1_baseline m2_robust using "output/ch09_diagnostics.rtf", ///
    replace b(%9.3f) se(%9.3f) ///
    title("OLS baseline diagnostics comparison") ///
    mtitles("Classic SE" "Robust SE") ///
    stats(N r2, labels("N" "R-squared"))

Quick-reference table of diagnostics:

Table 9.8 The complete four-diagnostic workflow.

L5|L5|L5|L5|L5

Command & Assumption tested & Null H0 & What p < 0.05 means & Fix
estat hettest & A5 homoskedasticity & constant residual variance & heteroskedasticity present & vce(robust)
estat imtest, white & A5 homoskedasticity & constant residual variance & heteroskedasticity present & vce(robust)
estat vif & A3 no collinearity & no linear dependence among regressors & VIF > 10 severe collinearity & drop / merge variables
estat ovtest & A1 linear specification & model correctly specified & omitted nonlinearity / interactions & add polynomials or interactions\

△  Integrity reminder (S9.1 preview): when diagnostics look bad, the correct response is fix the model or report the limitation honestly—never “keep swapping variable combinations until every diagnostic passes.” That is a variant of p-hacking.

§9.1 OLS Baseline Regression (Part 2): Steps 1–2 of the Six-Step Workflow ​

Core idea: robust standard errors are not “icing on the cake” but the minimum threshold for journal publication. Only with the six-step panorama in view do you know where you currently stand.

9.1.6 Robust Standard Errors: From “It Runs” to “It Publishes” ​

After diagnosing heteroskedasticity in the previous section, the fix is vce(robust). But you also need to know: in panel data, observations of the same bank in different years are not independent (within-group autocorrelation), requiring a stronger correction—cluster-robust standard errors.

* -- Comparing three types of standard errors --
use "data/clean/bank_panel.dta", clear

* Option A: classic SEs (assumes A5 homoskedasticity + A2 independence)
reg roe size leverage governance board_size
* output label: (no special label = classic SEs)

* Option B: heteroskedasticity-robust SEs (Huber-White, relaxes A5)
reg roe size leverage governance board_size, vce(robust)
* output label: (robust SE)

* Option C: cluster-robust SEs (relaxes A5 + A2; recommended for panels)
reg roe size leverage governance board_size, vce(cluster bank_id)
* output label: (cluster SE)
* meaning: residuals of the same bank across years may correlate

* -- Selection rules --
* 1. Cross-section + unsure about homoskedasticity -> vce(robust) is always safe
* 2. Panel -> vce(cluster unit-ID) is the minimum requirement
* 3. Number of clusters G < 50 -> consider wild cluster bootstrap (advanced)

Choosing among the three:

Table 9.9 Robust standard errors: from “it runs” to “it publishes”.

L4|L4|L4|L4

Data structure & Recommended SE & Stata syntax & Rationale
Cross-section (independent obs) & robust & vce(robust) & guards against heteroskedasticity
Panel (same unit, multiple periods) & clustered & vce(cluster bank_id) & within-unit residual autocorrelation
Panel + common time shocks & two-way clustered & reghdfe ..., vce(cluster bank_id year) & unit and time dependence at once\

9.1.6 The stata-mcp Six-Step Workflow at a Glance ​

The six-step workflow is this handbook’s master outline for empirical analysis—from description to conclusion, every step has explicit Stata commands and deliverables. Chapter 9’s §9.1–§9.7 map exactly onto these six steps:

+----------------------------------------------------------------+
|            stata-mcp six-step workflow (empirical pipeline)      |
+----------------------------------------------------------------+
|                                                                |
|  Step 1 . Descriptive statistics                               |
|  -----------------                                             |
|  §8.2 data physical + §8.3-8.4 univariate/bivariate analysis   |
|  Commands: summarize / tab / correlate / winsor2               |
|  Output: Tables 1-3 (descriptives), Figures 1-3 (distributions)|
|                                                                |
|  Step 2 . Baseline regression                                  |
|  -----------------                                             |
|  §9.1-9.2 OLS / panel fixed-effects regression                 |
|  Commands: reghdfe ... vce(cluster bank_id)                    |
|  Output: Table 4 (baseline: pooled/FE/RE/two-way FE columns)   |
|                                                                |
|  Step 3 . Diagnostic tests                                     |
|  -----------------                                             |
|  §9.2 post-regression diagnostics: heteroskedasticity,         |
|  autocorrelation, multicollinearity                            |
|  Commands: hettest / vif / estat bgodfrey / estat abar         |
|  Output: diagnostics recorded in the log file                  |
|                                                                |
|  Step 4 . Endogeneity treatment                                |
|  -----------------                                             |
|  §9.3 IV / §9.4 DID / §9.5 PSM-RDD                            |
|  Commands: ivregress 2sls / didregress / psmatch2 / rdrobust   |
|  Output: Table 5 (endogeneity-treatment results)               |
|                                                                |
|  Step 5 . Robustness checks                                    |
|  -----------------                                             |
|  §9.6 three groups of checks + specification curve             |
|  Commands: alternative variables / SEs / subsample regressions |
|  Output: Table 6 (robustness) + Figure (specification curve)   |
|                                                                |
|  Step 6 . Heterogeneity and mechanism tests                    |
|  -----------------                                             |
|  §9.7 split-sample regressions + mediation                     |
|  Commands: subgroup reghdfe + Baron-Kenny three steps          |
|  Output: Table 7 (mechanism) + Table 8 (heterogeneity)         |
|                                                                |
+----------------------------------------------------------------+

[Takeaway] AI assistance note: with stata-mcp you can paste diagnostic output to the AI and ask “what potential problems does this set of results have”—a legitimate use under S9.4 (AI interprets output; it does not generate coefficients).

9.1.7 Side Examples: OLS Baseline Variants in Your Field ​

The main example uses bank ROE panel data. Your field differs, but the six-step logic is identical—only the variables change. Below are baseline specifications for the three directions:

【Finance】 Determinants of Capital Structure ​

Research question: how do firm characteristics affect capital structure (debt-to-asset ratio)? Regression tests of three theoretical hypotheses.

* -- [Finance] capital-structure baseline --
* Hypotheses:
*   Trade-off theory   -> higher profitability -> lower leverage (internal funds first)
*   Pecking order      -> higher profitability -> lower leverage (same sign, different mechanism)
*   Market timing      -> higher market-to-book -> lower leverage (equity when overvalued)
*
* Model: lev = b0 + b1*size + b2*roe + b3*mtb + b4*tangibility + e
reg lev size roe mtb tangibility, vce(robust)
estat hettest
estat vif
【Insurance】 Determinants of Agricultural-Insurance Demand ​

Research question: how do farmer characteristics affect agricultural-insurance participation?

* -- [Insurance] ag-insurance demand (continuous DV: premium/coverage) --
* Hypotheses:
*   risk aversion -> take-up willingness up
*   loss aversion -> insurance demand up
*   income -> ability to pay up -> take-up up
*
* Model: ins_premium = b0 + b1*risk_aversion + b2*loss_aversion + b3*income + b4*farm_size + e
reg ins_premium risk_aversion loss_aversion income farm_size, vce(robust)
estat hettest
estat vif
* Note: if the DV is 0/1 (take-up), switch to logit/probit
【Agriculture】 Microfinance Loan Access ​

Research question: how do joint liability and dynamic incentives affect farmers’ loan access?

* -- [Agriculture] microfinance loan access --
* Hypotheses:
*   joint liability (group_loan=1) -> loan access up (peer monitoring cuts defaults)
*   dynamic incentive (repeat_borrower) -> loan size up (reputation effect)
*
* Model: loan_access = b0 + b1*group_loan + b2*repeat_borrower + b3*income + b4*education + e
reg loan_access group_loan repeat_borrower income education, vce(robust)
estat hettest
estat vif
estat ovtest

Guided Exercise 1 ​

Steps:

  1. Open your research folder and confirm data/clean/bank_panel.dta exists (if not, regenerate it from §1.4)

  2. Create a new do-file code/ch09_exercise1_ols_diagnosis.do

  3. Complete the following six steps in order:

    • Step A: use "data/clean/bank_panel.dta", clear

    • Step B: reg roe size leverage governance board_size (baseline OLS)

    • Step C: estat hettest + estat imtest, white (heteroskedasticity) → record p values and state your judgment

    • Step D: estat vif (collinearity) → record Mean VIF and state your judgment

    • Step E: estat ovtest (specification error) → record the p value and state your judgment

    • Step F: reg roe size leverage governance board_size, vce(robust) → compare the SE changes between Step B and Step F

  4. At the end of the do-file, write a 3–5 sentence diagnostic summary in a * Conclusion: comment

  5. Run the do-file and save the log to output/ch09_ex1.log

Self-check list:

  • Did you record the p values of all four diagnostics?

  • Can you say “what to do when p < 0.05”?

  • Is the gap between classic and robust SEs large? If so, what does that imply?

  • Is the log complete (from use to the last command)?

△  S9.4 reminder: every coefficient, standard error, and p value in this step must come from your own Stata run. Asking AI to “make up a set of regression results” is academic fraud. AI’s legitimate uses are writing code and interpreting output.

§9.2 Panel Data: FE and RE ​

Core idea: the value of panel data is that it lets you control for omitted variables that are unobservable but time-invariant—something OLS cannot do. Fixed effects (FE) address exactly the “time-invariant omitted variables” threat among Chapter 4’s seven validity threats.

9.2.1 What Is Panel Data? Why Use Panels? ​

Panel data = the same unit observed repeatedly over multiple time points. The main dataset bank_panel.dta is a panel of 100 banks × 5 years (2020–2024) = 500 observations.

* -- Declare the panel structure --
use "data/clean/bank_panel.dta", clear
xtset bank_id year
* Reading the output:
*   panel variable:  bank_id (strongly balanced)
*   time variable:   year
*   series:          2020 2021 2022 2023 2024
*   delta:           1 unit
*
* "strongly balanced" = every bank has all 5 years (no missing periods)
* "weakly balanced" = some units miss some years

* Confirm the structure
xtdescribe
* shows number of units, time span, and balance

Why is a panel better than a pure cross-section?

Table 9.10 What is panel data? Why use panels?

L3|L3|L3

Data type & Omitted variables it controls & What it cannot control
Cross-section & observable variables (put into the regression) & all unobservables
Panel + FE & observables + time-invariant unobservables & time-varying unobservables
Panel + FE + time effects & the above + time shocks common to all units & omitted variables varying with both unit and time\

[Takeaway] Link to Chapter 4: Chapter 4 lists seven threats to internal validity—history / maturation / testing / instrumentation / statistical regression / selection bias / attrition. FE mainly addresses the subcategory of selection bias arising from time-invariant omitted variables (e.g., a bank’s corporate culture or its region’s financial ecology—unobservable, yet essentially constant over 5 years).

9.2.2 Within Estimation (FE) vs GLS Random Effects (RE) ​

Fixed effects (FE): subtract each variable’s unit mean (demeaning), thereby annihilating all time-invariant unit characteristics—whether observed or not.

math
y_{it} - \bar{y}_i = \beta_1(x_{1it} - \bar{x}_{1i}) + \cdots + (\varepsilon_{it} - \bar{\varepsilon}_i)

Random effects (RE): assume the unit effect ui is uncorrelated with the regressors (E(ui∣xit)=0), and use GLS to weight within and between information; more efficient than FE (smaller SEs).

Table 9.11 Within estimation (FE) vs GLS random effects (RE).

L3|L3|L3

Dimension & FE (fixed effects) & RE (random effects)
Key assumption & unit effect may correlate with regressors & unit effect uncorrelated with regressors
Estimation & OLS on demeaned data & GLS (within + between information)
Efficiency & lower (within variation only) & higher (uses information more fully)
Consistency & weaker assumptions; almost always consistent & strong assumption; inconsistent if violated
Can it estimate time-invariant regressors? & ❌ no (demeaned away) & ✅ yes
When to use & when unsure whether the unit effect correlates with x & when theory supports no correlation\

* -- FE and RE estimation (continuing the Chapter 1 three-model setup) --
xtset bank_id year

* Model 2: fixed effects (FE)
xtreg roe size leverage governance board_size, fe
estimates store m2_fe
* Key output:
*   R-sq: within = 0.XXX  <- within explanatory power (FE's core metric)
*   F test that all u_i=0: F(99, 396) = XX.XX, Prob > F = 0.0000
*   -> p < 0.05 means unit effects are jointly significant; FE beats pooled OLS

* Model 3: random effects (RE)
xtreg roe size leverage governance board_size, re
estimates store m3_re
* Key output:
*   corr(u_i, X) = 0  <- RE assumes this is zero
*   sigma_u / sigma_e ratio <- share of unit effect in total variance

9.2.3 The Hausman Test: FE or RE? ​

The Hausman test is the referee between FE and RE—it tests the core question: is the unit effect ui correlated with the regressors?

* -- Hausman test --
hausman m2_fe m3_re
* H0: the FE and RE coefficients do not differ systematically
*     (unit effect uncorrelated with x -> RE consistent and efficient)
* H1: differences are systematic (unit effect correlated with x ->
*     RE inconsistent -> must use FE)
*
* Reading the output:
*   chi2(4) = (b-B)'[(V_b-V_B)^(-1)](b-B) = XX.XX
*   Prob > chi2 = 0.XXXX
*
* Decision rules:
*   p < 0.05 -> reject H0 -> choose FE (RE biased)
*   p > 0.05 -> fail to reject H0 -> choose RE (more efficient, unbiased)
*   p ~ 0.05 (borderline) -> choose FE to be safe
*
* -- Notes on the Hausman test --
* 1. estimates store the two models first
* 2. "not positive definite" usually means RE has problems; just use FE
* 3. Hausman presumes FE itself is consistent---if FE is also
*    inconsistent (time-varying omitted variables), the test is
*    meaningless -> need IV/DID (§9.3-§9.4)

Hausman decision table:

Table 9.12 The Hausman test: FE or RE?

L4|L4|L4|L4

Hausman p & Conclusion & Choice & Rationale
p < 0.01 & strongly reject H0 & FE & unit effect highly correlated with x
0.01 ≤ p < 0.05 & reject H0 & FE & correlation present; RE inconsistent
0.05 ≤ p < 0.10 & borderline & FE (conservative) & consistency over efficiency
p ≥ 0.10 & fail to reject H0 & RE & no evidence of correlation; RE more efficient\

9.2.4 The BP-LM Test: RE or Pooled OLS? ​

Hausman answered “FE vs RE.” But there is a prior question: is RE better than ignoring the panel structure (pooled OLS)? The Breusch-Pagan Lagrange Multiplier test answers it.

* -- BP-LM test (install xttest0 first) --
* ssc install xttest0    // install on first use

* Run the RE model first
xtreg roe size leverage governance board_size, re

* BP-LM test
xttest0
* H0: sigma2_u = 0 (no unit effect -> pooled OLS suffices)
* H1: sigma2_u > 0 (unit effect exists -> RE/FE beats pooled OLS)
*
* Reading the output:
*   Breusch and Pagan Lagrangian Multiplier Test for random effects
*   chibar2(01) = XX.XX
*   Prob > chibar2 = 0.XXXX
*
* Decision rules:
*   p < 0.05 -> significant unit effects -> RE/FE over pooled OLS
*   p > 0.05 -> no unit effects -> pooled OLS suffices

The complete panel-model selection flow:

Step 1: pooled OLS vs RE -> BP-LM test (xttest0)
        +-- p > 0.05 -> pooled OLS (no panel effect)
        +-- p < 0.05 -> go to Step 2

Step 2: FE vs RE -> Hausman test
        +-- p < 0.05 -> use FE
        +-- p > 0.05 -> use RE

9.2.5 reghdfe: High-Dimensional Fixed Effects, Efficiently ​

When the panel is large (100 banks × 5 years = 500 obs is fine, but 3000 firms × 10 years = 30,000 obs is not), traditional xtreg, fe becomes slow. reghdfe, a community-developed high-performance alternative, can also absorb multiple fixed-effect dimensions at once.

* -- reghdfe high-dimensional fixed effects --
* ssc install reghdfe    // install on first use
* ssc install ftools     // reghdfe depends on ftools

* Basic usage (equivalent to xtreg, fe but faster)
reghdfe roe size leverage governance board_size, absorb(bank_id) vce(cluster bank_id)
* absorb(bank_id) = absorb bank fixed effects
* vce(cluster bank_id) = cluster-robust standard errors

* reghdfe vs xtreg (results should be identical)
xtreg roe size leverage governance board_size, fe vce(cluster bank_id)
* -> compare coefficients and SEs to verify equivalence

* Advantages of reghdfe:
*   1. Speed: 10-100x faster than xtreg on large samples
*   2. Multi-dimensional FE: absorb several dimensions at once
*   3. Flexible: F tests after partialling out

9.2.6 Two-Way Fixed Effects (Unit + Time) ​

In reality, not only do banks differ in “innate conditions” (unit effects), but different years carry common macro shocks (time effects, e.g., the 2020 pandemic, the 2023 rate cuts). Two-way FE controls both simultaneously.

* -- Two-way fixed effects --
* Method 1: reghdfe absorbs directly (recommended, cleanest)
reghdfe roe size leverage governance board_size, ///
    absorb(bank_id year) vce(cluster bank_id)
estimates store m4_twoway

* absorb(bank_id year) = absorb unit FE and time FE together
* meaning: each bank has its own intercept, and each year too

* Method 2: xtreg + year dummies (equivalent, easier to understand)
tab year, gen(yr_)           // create year dummies yr_2018-yr_2023
xtreg roe size leverage governance board_size yr_2019-yr_2023, ///
    fe vce(cluster bank_id)
estimates store m4_twoway_xt

* The two are identical (same coefficients and SEs)
* reghdfe is cleaner, especially with many dimensions
* (e.g., absorb(bank_id year province))

* -- Four-model comparison table --
esttab m1_pooled m2_fe m3_re m4_twoway using "output/table_9_2.tex", ///
    replace b(%9.3f) se(%9.3f) scalars("r2_w Within R2") ///
    mtitles("Pooled OLS" "FE" "RE" "Two-way FE") ///
    stats(N r2 r2_w, labels("N" "R2" "Within R2")) ///
    note("SEs clustered at bank level; * p<0.10, ** p<0.05, *** p<0.01")

Full mapping to Chapter 4’s validity threats:

Table 9.13 Two-way fixed effects (unit + time).

L3|L3|L3

Model & Validity threats controlled (Ch. 4) & Not controlled
Pooled OLS & observables only & all unobservables
FE (unit) & time-invariant omitted variables (bank culture, regional traits) & time-varying omissions (e.g., changing managerial ability)
Two-way FE (unit+time) & the above + time shocks common to all units (macro policy) & omissions varying with both unit and time
IV (§9.3) & omitted variables + reverse causality & depends on instrument validity
DID (§9.4) & history effects + selection bias & depends on parallel trends\

9.2.7 Complete Panel-Analysis Workflow (Template) ​

* ======================================================
* §9.2 complete panel-analysis workflow template
* ======================================================
clear all
set more off
capture log close
log using "output/ch09_panel_analysis.log", replace

% --- 0. Load data and set the panel ---
use "data/clean/bank_panel.dta", clear
xtset bank_id year
* check panel structure: balanced/unbalanced, time span
xtdes

% --- 1. Descriptive statistics ---
summarize roe size leverage governance board_size car npl_ratio
pwcorr roe size leverage governance board_size, star(0.05)

% --- 2. Baseline regressions: four models ---
* (a) pooled OLS
reg roe size leverage governance board_size, vce(robust)
estimates store m1_pooled

* (b) unit fixed effects
reghdfe roe size leverage governance board_size, ///
    absorb(bank_id) vce(cluster bank_id)
estimates store m2_fe

* (c) random effects
xtreg roe size leverage governance board_size, re vce(robust)
estimates store m3_re
hausman m3_re m2_fe   // Hausman: p<0.05 -> choose FE

* (d) two-way fixed effects (unit + time)
reghdfe roe size leverage governance board_size, ///
    absorb(bank_id year) vce(cluster bank_id)
estimates store m4_twoway

% --- 3. Diagnostics ---
* multicollinearity
vif                      // VIF > 10 needs attention
* heteroskedasticity (only for pooled OLS)
hettest                  // p<0.05 -> heteroskedastic -> use robust
* within autocorrelation
estat bgodfrey           // p<0.05 -> autocorrelation -> cluster

% --- 4. Export the comparison table ---
esttab m1_pooled m2_fe m3_re m4_twoway using "output/table_9_2.tex", ///
    replace b(%9.3f) se(%9.3f) ///
    mtitles("Pooled OLS" "FE" "RE" "Two-way FE") ///
    stats(N r2 r2_w, labels("N" "R2" "Within R2")) ///
    note("SEs clustered at bank level; * p<0.10, ** p<0.05, *** p<0.01")

log close
display "=== panel analysis complete ==="

Guided Exercise 2 ​

Steps:

  1. Create a new do-file code/ch09_exercise2_panel.do

  2. Follow the §9.2.7 template through Steps 1–8

  3. Record the following judgments as comments in the code:

    • What is the BP-LM p value? → what is your conclusion?

    • What is the Hausman p value? → FE or RE?

    • Do coefficients change much between two-way and one-way FE? → are time effects important?

  4. Run the do-file and confirm output/panel_four_models.rtf was generated

  5. Open the RTF and check whether the four columns’ coefficients are sensible (consistent signs, similar magnitudes)

Advanced challenge (optional):

  • Swap the main example for your own data (e.g., the macro panel downloaded in Chapter 6) and repeat the whole workflow

  • Think: if your Hausman p = 0.03 (just below 0.05), what would you choose, and why?

Self-check list:

  • Does xtset print “strongly balanced” or “weakly balanced”? Do you know the difference?

  • FE’s Within R² is usually lower than pooled OLS’s R²—is that normal? Why?

  • Does your Hausman conclusion match what you got in §1.4 of Chapter 1?

  • In two-way FE, absorb(bank_id year) absorbs 100 + 5 - 1 = 104 parameters—what does that do to the degrees of freedom?

△  S9.4 reminder: every coefficient, Hausman statistic, and BP-LM value in panel analysis must come from your own Stata run. AI can help you understand “why choose FE” but cannot “make up a Hausman p value” for you.

§9.3–§9.5 Method-Selection Decision Tree (Identification Strategies at a Glance)

📐 结构图示(书版示意图的文字要点)

  1. tikzpicture
  2. ->,thick
  3. no
  4. yes

Figure 9.2 The causal-identification decision tree—starting from “is there endogeneity,” proceeding layer by layer through “selection on observables? / exogenous variation? / a cutoff?”

§9.3 Instrumental Variables (IV/2SLS) ​

Core idea: when a regressor correlates with the error term (endogeneity), OLS is biased and inconsistent. The core idea of IV: find an “exogenous pusher” that affects the outcome only through the endogenous regressor, thereby isolating the “clean” part of the endogenous variable.

9.3.1 The Three Sources of Endogeneity ​

Among the five classic OLS assumptions of §9.1, we require E(ε|X) = 0—regressors uncorrelated with the error. When this fails, endogeneity appears. Three sources:

Table 9.14 The three sources of endogeneity.

L4|L4|L4|L4

Source & Mechanism & Finance example & Consequence
Omitted-variable bias & a variable affecting both X and Y is left out & bank management ability drives both governance and roe, but “ability” is unobservable & β^ biased and inconsistent
Reverse causality & Y feeds back into X & profitable banks afford better governance → good governance; but good governance also lifts profit → two-way causation & β^ biased and inconsistent
Measurement error & X is measured with noise & self-reported “financial literacy” scores carry systematic bias & attenuation bias in β^\

[Key] Rule of thumb for endogeneity: if your core regressor is a “behavior” (insuring, borrowing, attending training) or an “institutional trait” (governance, ownership structure), endogeneity is almost certain—because choice and behavior are inherently non-random.

9.3.2 The Two Conditions for a Valid Instrument ​

A qualified instrument Z must satisfy both:

Condition 1: Relevance
   Z is significantly correlated with the endogenous X
   -> testable: first-stage F statistic > 10 (Stock & Yogo, 2005)

Condition 2: Exclusion restriction
   Z affects Y only through X; no other direct path to Y
   -> NOT testable! argued only from economic theory and institutions

A graphical understanding:

         Z (instrument)
         |
         | (1) Z -> X (relevance: testable)
         v
    X (endogenous) -------> Y (outcome)
         ^               ^
         |               |
         +--- U ---------+  (2) omitted U drives both X and Y
                            (the source of endogeneity)

   Exclusion restriction: no arrow from Z to Y except through X
   (i.e., Z is independent of U)

9.3.3 Implementing 2SLS in Stata ​

Main example: the effect of corporate governance (governance) on bank profitability (roe). We worry governance is endogenous (omitted variables + reverse causality), so we use the average governance of other banks in the same industry (industry_avg_governance) as the instrument.

The IV logic: the industry average correlates with this bank’s governance (demonstration effects, converging regulatory standards) but does not directly affect this bank’s ROE (exclusion: other banks’ governance reaches this bank’s profit only through “industry-norm pressure” on its governance).

* -- §9.3 full IV/2SLS workflow --
* Data: bank_panel.dta (100 listed banks x 5 years)
use data/clean/bank_panel.dta, clear
xtset bank_id year

* Step 1: OLS baseline (for comparison)
reg roe size leverage governance board_size, vce(cluster bank_id)
est store m1_ols

* Step 2: 2SLS estimation
* syntax: ivregress 2sls depvar exogvars (endog = instruments), options
ivregress 2sls roe size leverage board_size ///
    (governance = industry_avg_governance), ///
    vce(cluster bank_id)
est store m2_iv

* Reading the output:
*   the IV coefficient on governance = causal effect purged by the instrument
*   IV > OLS -> OLS may understate the causal effect (attenuation or
*              reverse-causality dilution)
*   IV < OLS -> OLS may overstate (positive omitted-variable bias)

9.3.4 Weak-Instrument Test: The First-Stage F Statistic ​

* -- First-stage diagnostics --
estat firststage

* Reading the output:
*   focus on the F statistic (Kleibergen-Paap rk Wald F)
*   decision rules:
*     F >= 10  -> not weak; 2SLS credible (Stock & Yogo critical values)
*     F < 10   -> weak instrument! 2SLS may be severely biased,
*                 possibly worse than OLS
*
*   sample output:
*   Kleibergen-Paap rk Wald F statistic = 15.32
*   read: F = 15.32 > 10 -> not weak; trust the 2SLS results
*
*   if F = 3.8 < 10:
*   -> correlation between instrument and endogenous regressor too weak
*   -> find a stronger instrument, or abandon the IV strategy

Consequences of weak instruments (make sure you understand):

Table 9.15 Weak-instrument test: the first-stage F statistic.

L3|L3|L3

First-stage F & Consequence & Response
F > 10 & fine; 2SLS consistent and approximately normal & report directly
5 < F < 10 & gray zone; possible finite-sample bias & add Anderson-Rubin confidence intervals
F < 5 & severely weak; 2SLS may be worse than OLS & abandon this IV; find another\

9.3.5 Overidentification Tests (Sargan / Hansen J) ​

When you have multiple instruments (more instruments than endogenous regressors), you can test whether “the surplus instruments satisfy the exclusion restriction”:

* -- Overidentification test (two instruments) --
ivregress 2sls roe size leverage board_size ///
    (governance = industry_avg_governance regulatory_pressure), ///
    vce(cluster bank_id)

* Hansen J test (heteroskedasticity-robust version; prefer this)
estat overid

* Reading the output:
*   H0: all instruments satisfy the exclusion restriction
*       (the overidentifying restrictions are valid)
*   p > 0.05 -> fail to reject H0 -> instruments acceptable as a set
*   p < 0.05 -> reject H0 -> at least one instrument violates exclusion;
*               investigate one by one
*
*   example: Hansen J chi2(1) = 0.82, p = 0.365
*   read: p = 0.365 > 0.05 -> restrictions not rejected; the two IVs pass

△  Note: when the number of instruments equals the number of endogenous regressors (just-identified), the overidentification test is unavailable—the exclusion restriction cannot be tested statistically at all and must be argued from economic logic.

9.3.6 Common Instruments in Finance ​

Table 9.16 Common instruments in finance.

L4|L4|L4|L4

IV type & Concrete variable & Applicable setting & Exclusion argument
Industry/region averages & average X of other firms in the same industry & firm-level endogenous regressors (governance, leverage, R&D) & other firms’ traits do not directly affect this firm’s outcome
Policy shocks & batch/timing differences of pilot programs & policy evaluation (digital-finance pilots, green-credit policy) & batch assignment is administrative, unrelated to firm performance
Geographic variables & distance to financial centers, elevation, river density & financial access, insurance coverage & geography is “natural,” unaffected by individual behavior
Historical variables & historical financial infrastructure (e.g., Republican-era native banks) & current financial development & history shapes institutions via path dependence, not current individual outcomes directly
Institutional variables & legal origin, regulatory-framework differences & cross-country/cross-region comparisons & institutions are historically determined, not chosen by firms\

[Takeaway] AI-assistance note: you may paste your hypothesis to the AI and ask “what instruments are possible in this setting? Is the exclusion restriction plausible?”—but the final IV choice and argument are your scholarly judgment and cannot be outsourced to AI (S9.4 red line).

Guided Exercise 3 ​

Task: run the full IV/2SLS workflow and diagnostics with bank_panel.dta.

  1. Load the data and set the panel: use data/clean/bank_panel.dta, clear + xtset bank_id year

  2. Run the OLS baseline: reg roe size leverage governance board_size, vce(cluster bank_id); record the governance coefficient

  3. Run 2SLS:

ivregress 2sls roe size leverage board_size ///
    (governance = industry_avg_governance), vce(cluster bank_id)
  1. Test for weak instruments: estat firststage; record the F and judge whether > 10

  2. Compare OLS and IV coefficients: did the governance coefficient grow or shrink? Try to explain the direction

  3. (Advanced) If you can find a second instrument, add it, run estat overid, and interpret the Hansen J p value


Echoing Chapter 4’s Validity Threats ​

Chapter 4 §4.2 defined seven internal-validity threats. IV mainly addresses the following:

Table 9.17 Echoing Chapter 4’s validity threats.

L2|L2

Chapter 4 threat & How IV responds
Selection bias & when “participation” is non-random (banks that improve governance voluntarily are good banks anyway), IV breaks self-selection with exogenous variation, making the “pushed-by-instrument” part approximately random
History (indirectly) & if external events hit both X and Y, a good IV is unrelated to those events (exclusion), so IV estimates are immune to history\

In Chapter 4’s language: IV converts the question “did it do it” into “is there an exogenous pusher that proves it did.” If the first-stage F > 10 and the exclusion argument stands, you have an effective defense against selection bias and omitted-variable bias.

§9.4 Difference-in-Differences (DID) ​

Core idea: DID is one of the “gold standards” of policy evaluation. The intuition is simple—use the control group’s “natural change” to net out the treatment group’s “natural change”; what remains is the policy’s causal effect. DID is essentially the interaction term of a 2×2 factorial design.

Scenario: in 2019 a province launched a “digital-finance demonstration zone” policy; you want to know whether it raised local banks’ ROE.

                    pre-policy (2018)   post-policy (2020)   change
   Treated (demo prov.)   roe_T,pre       roe_T,post     dT = roe_T,post - roe_T,pre
   Control (other prov.)  roe_C,pre       roe_C,post     dC = roe_C,post - roe_C,pre

   DID estimator = dT - dC
                 = (treated change) - (control change)

Why a “double” difference?

  • A single difference (treated pre/post ΔT) contains the policy effect + time trend (macro recovery, industry rebound, etc.)

  • A cross-sectional difference (treated post minus control post) contains the policy effect + innate group differences

  • Double differencing: ΔT−ΔC removes both the “common time trend” and the “innate level gap”

[Key] Key assumption: parallel trends—absent the policy, the treatment and control groups’ outcome variables should move along parallel trajectories. Levels need not be equal; only trends must match.

9.4.2 The 2×2 Factorial Essence (★ Core of This Section) ​

Echoing §9.0: in the GLM umbrella we learned the general linear model of a 2×2 factorial design:

math
y = \beta_0 + \beta_1 \cdot x_1 + \beta_2 \cdot x_2 + \beta_3 \cdot x_1 \cdot x_2 + \varepsilon

where β1 and β2 are main effects and β3 is the interaction effect.

DID is a direct application of this formula:

Table 9.18 The 2×2 factorial essence (core of this section).

L3|L3|L3

Factorial term & DID term & Meaning
x1 (factor 1) & treat (treatment dummy) & 1 = treated, 0 = control
x2 (factor 2) & post (time dummy) & 1 = post-policy, 0 = pre-policy
β1 (main effect 1) & treat coefficient & innate level gap between groups
β2 (main effect 2) & post coefficient & common time trend
β3 (interaction) & treat × post coefficient & = DID estimator = policy causal effect\

“The regression coefficients β1 and β2 provide effect-size estimates of the main effects, while β3 provides the effect-size estimate of the interaction effect.”

The DID regression equation:

math
roe_{it} = \beta_0 + \beta_1 \cdot treat_i + \beta_2 \cdot post_t + \beta_3 \cdot (treat_i \times post_t) + \gamma \cdot X_{it} + \varepsilon_{it}
* -- 2x2 DID basic regression --
use data/clean/bank_panel.dta, clear

* Create the DID variables
gen treat = (province == "Demonstration")   /* treatment marker */
gen post  = (year >= 2019)                 /* post-policy marker */
gen did   = treat * post                   /* interaction = DID estimator */

* Run the DID regression
reg roe treat post did size leverage, vce(cluster bank_id)

* Reading the output:
*   did coefficient b3 = causal policy effect (ATT)
*   if b3 = 1.2, p < 0.05 -> the zone policy raised ROE by ~1.2 pp
*   treat coefficient = innate gap between the two groups
*   post coefficient = common time trend shared by both groups

Key warning: “If β3 is significant…… we cannot significantly interpret the independent effects of course type (β1) or teaching time (β2), because the two effects cannot be distinguished. Only when the interaction is insignificant can the main effects be interpreted.”

Mapped to DID: when the interaction treat×post is significant (the policy has an effect), the main-effect coefficients of treat and post should not be read separately as “treatment-group traits” or “time trend”—the interaction has “absorbed” part of their meaning. Only when the DID estimator is insignificant can treat and post be interpreted as independent group differences and time trends.

Parallel trends is DID’s Achilles’ heel. How to test it?—the event study: create dummies for each pre-policy period and check whether treatment-control differences are zero before the policy.

* -- Testing parallel trends with an event study --
* Install first: ssc install eventstudyinteract

* Create relative-time dummies (baseline = one period before policy)
gen rel_time = year - 2019   /* -3, -2, -1, 0, 1, 2 */

* Estimate dynamic effects with eventstudyinteract
eventstudyinteract roe L3.rel_time L2.rel_time L1.rel_time ///
    F0.rel_time F1.rel_time F2.rel_time, ///
    vce(cluster bank_id) treat(treat) base(0)
* L3.rel_time = 3rd pre-period, L1.rel_time = 1st pre-period (omitted base)
* F0.rel_time = policy period, F1.rel_time = 1st post period

* Plot the event-study figure (dynamic effects)
coefplot, keep(L3.rel_time L2.rel_time L1.rel_time ///
    F0.rel_time F1.rel_time F2.rel_time) ///
    vertical yline(0, lpattern(dash) lcolor(red)) ///
    ciopts(recast(rcap)) ///
    xtitle("Time relative to policy") ytitle("Dynamic treatment effect") ///
    title("Event study: parallel-trends test") ///
    note("Pre-policy coefficients should not differ from 0")
graph export "figures/event_study.pdf", replace

* Joint test: are the pre-policy coefficients jointly zero?
* eventstudyinteract reports a Wald test automatically
*
*   [!] significant pre-policy coefficients -> parallel trends fail
*   -> the DID result is not credible
*   -> change the control group, shorten the window, or switch to
*      synthetic control

Decision rules:

Table 9.19 The parallel-trends assumption and event studies.

L3|L3|L3

Test result & Reading & Next step
joint F test on pre-policy coefficients p > 0.10 & parallel trends hold & use DID with confidence
one or two periods significant but no trend & likely random fluctuation & add placebo tests
systematic pre-policy trend & parallel trends fail & switch methods (synthetic control / matching + DID)\

9.4.4 Staggered DID and Heterogeneous Treatment Effects ​

In reality, policies are rarely implemented all at once—different regions enter the pilot in different years (staggered adoption). The traditional two-way fixed-effects (TWFE) DID becomes biased under staggered adoption plus heterogeneous treatment effects (Goodman-Bacon, 2021; de Chaisemartin & D’Haultfœuille, 2020).

* -- Staggered DID: did_multiplegt --
* Install first: ssc install did_multiplegt

* Suppose banks are hit by the policy in different years
* first_treat: the first treatment year per unit (0 or large if never)

did_multiplegt roe bank_id year treat, ///
    robust_dynamic dynamic(3) placebo(3) ///
    breps(200) cluster(bank_id)

* Reading the output:
*   "Average cumulative effect" = cumulative average treatment effect
*   "Dynamic effect" reported by event time -> draw an event-study plot
*   compare with traditional TWFE: large gaps -> heterogeneous effects
*
*   [!] Heterogeneous-treatment-effect warning:
*   if early-treated units' effects differ from late-treated units'
*   -> the TWFE DID coefficient is a weighted average of 2x2 DIDs,
*      and some weights may be NEGATIVE!
*   -> must use did_multiplegt / callaway / sun_abraham instead

9.4.5 Clustering Standard Errors at the Treatment-Assignment Level ​

DID standard errors must be clustered at the treatment-assignment level, not the individual level:

* -- Correct vs incorrect standard errors --

* [x] Wrong: cluster at the individual (bank_id) if policy is provincial
reg roe treat post did size leverage, vce(cluster bank_id)

* [v] Correct: cluster at the policy-assignment level (province)
reg roe treat post did size leverage, vce(cluster province)

* Decision rule:
*   cluster at the level where treatment is assigned
*   e.g.: provincial pilot -> cluster(province)
*         industry regulation -> cluster(industry)
*         bank-level treatment -> cluster(bank_id)
*
*   the higher the clustering level, the smaller the effective
*   sample and the larger the SEs
*   Abadie et al. (2023): with few treated clusters, use wild bootstrap

Guided Exercise 4 ​

Task: run a complete DID analysis with bank_panel.dta.

  1. Construct treatment: suppose banks with bank_id 1–30 joined the “digital-governance demonstration” in 2019; generate treat, post, and did

  2. Run the 2×2 DID regression: reg roe treat post did size leverage, vce(cluster bank_id)

  3. Interpret the did coefficient—is it the causal policy effect? Why?

  4. Test parallel trends with an event study: generate treat×year interaction dummies for each pre-policy period and estimate with reghdfe

  5. Draw the event-study plot (coefplot): pre-policy coefficients should hover around zero

  6. (Advanced) Think: if different banks join the demonstration in 2018, 2019, and 2020, which method should you use? Why may traditional TWFE fail?


Echoing Chapter 4’s Validity Threats ​

Among Chapter 4 §4.2’s seven internal-validity threats, DID + parallel trends mainly addresses the following two:

Table 9.20 Chapter 4 threats / how DID responds.

L2|L2

Chapter 4 threat & How DID responds
History & “your study period happened to coincide with LPR cuts / the pandemic / property-market regulation”—DID absorbs all common external shocks through the control group. Provided these events hit both groups equally (parallel trends), differencing removes them
Selection bias & “the pilot counties were the province’s favored ones”—DID does not require equal levels (the treat main effect absorbs innate gaps); only equal trends. Thus even if the treated group is innately stronger, DID is unbiased as long as the two groups would have moved in parallel without the policy\

In Chapter 4’s language: DID hands the “history threat” to the control group for absorption, and converts “selection bias” into the testable question “do parallel trends hold?” That is why DID is so powerful in policy evaluation—it need not eliminate the source of selection bias, only require that the bias’s time pattern be predictable.

§9.5 Propensity-Score Matching (PSM) and Regression Discontinuity (RDD) ​

Core idea: PSM and RDD both try to “simulate a randomized experiment” in observational data—PSM constructs “approximately equivalent” controls by matching on observables; RDD exploits a cutoff in institutional rules to create a “locally randomized” comparison near the threshold.


Part A: Propensity-Score Matching (PSM) ​

9.5.1 Selection Bias and Constructing Observable Controls ​

The problem: in Chapter 4 §4.2 we called selection bias “the number-one killer of economic research”—people who voluntarily join insurance, borrow, or attend training differ from those who do not from the very start.

The core idea of PSM:

Ideal (RCT): random assignment -> treated ~ control (all traits balanced)
Reality (observational): self-selection -> treated != control

PSM's compromise:
  1. Estimate the "participation probability" (propensity score) from
     observable traits (size, leverage, region, industry...)
  2. Match each treated unit to the control unit with the closest score
  3. After matching, the two groups are "approximately equivalent"
     on observables
  4. Compare matched outcomes = ATT (average treatment effect on the treated)

△  PSM’s fundamental limitation: it can only balance observable traits. If unobservable confounders exist (“management ability,” “risk appetite”), PSM cannot help—then you need IV or DID.

9.5.2 Stata Implementation: psmatch2 and teffects psmatch ​
* -- Full PSM workflow --
use data/clean/bank_panel.dta, clear

* Suppose treat = 1 means the bank undertook digital transformation
* Goal: estimate the causal effect of transformation on ROE

* --- Method 1: psmatch2 (classic, detailed output) ---
* Install first: ssc install psmatch2
* Step 1: estimate the propensity score and match (1:3 nearest neighbor)
psmatch2 treat size leverage car board_size, outcome(roe) ///
    neighbor(3) common caliper(0.05)
*   treat = treatment variable (digital transformation = 1)
*   neighbor(3) = match 3 controls to each treated unit
*   common = restrict to the common support
*   caliper(0.05) = no match if score gap exceeds 0.05

* Inspect the matching result
pstest size leverage car board_size, both graph
* output: standardized bias (|SB|) and t tests for each variable

* --- Method 2: teffects psmatch (modern, more rigorous) ---
teffects psmatch (roe) (treat size leverage car board_size), ///
    nneighbor(3) caliper(0.05)
* Reading the output:
*   ATET = average treatment effect on the treated (same meaning as ATT)
*   teffects reports SEs and confidence intervals automatically
9.5.3 Match-Quality Diagnostics ​

Matching is not “run once and done”—you must prove the two groups are indeed “approximately equivalent” after matching.

* -- Diagnostic 1: common support --
* psmatch2 prints this automatically
sum _pscore if treat == 1   /* treated score range */
sum _pscore if treat == 0   /* control score range */

* Judge: the two score distributions should overlap substantially
* if min(treated) > max(control) -> no common support; matching failed

* -- Diagnostic 2: balance test --
pstest size leverage roa cost_income, t(treat)
* expected output:
*   Variables   |  Std. Bias  |  t-stat  |  p-value
*   ------------|-------------|----------|---------
*   size        |    3.2%     |   0.45   |  0.653
*   leverage    |    5.1%     |   0.78   |  0.436
*   roa         |    2.8%     |   0.31   |  0.758
*   cost_income |    4.6%     |   0.62   |  0.535
*   judge: all |SB| < 10%

* -- Diagnostic 3: before/after bias plot --
pstest size leverage roa cost_income, t(treat) graph
* expected: standardized-bias bars shrink markedly after matching

* -- Decision rule --
*   |SB| < 10%
*   -> balance good; matching valid
*   |SB| > 10% -> that variable unbalanced; adjust the matching
*   (e.g., increase neighbors, switch to kernel matching,
*    add more covariates)

Match-quality diagnostic checklist:

Table 9.21 Part A: propensity-score matching (PSM).

L4|L4|L4|L4

Diagnostic & Pass standard & Consequence of failing & Remedy
Common support & score distributions overlap ≥ 90% & many observations dropped; external validity falls & trimming or switch matching method
Standardized bias & all covariates after matching |SB|<10% & imbalance; ATT biased & re-specify the score or matching
Post-match sample size & ATT based on enough observations & low test power & relax the caliper or use IPW
Rosenbaum sensitivity & conclusion robust at Γ>1.5 & potential unobserved confounding & acknowledge the limitation and discuss direction\


Part B: Regression Discontinuity (RDD) ​

9.5.4 RDD Intuition: Approximate Randomization near the Cutoff ​

Scenario: a province rules that “banks with capital adequacy ≥10.5% qualify for an innovation license.” You want to know whether obtaining the license raised ROE.

       probability of license
  1.0 -----------------+
                        |  <- cutoff = 10.5%
  0.0 ------------------+
       --------------------------
       8%    9%   10%  10.5%  11%  12%
                    capital adequacy (running variable)

  Core intuition:
  a bank at 10.4% vs a bank at 10.6%
  -> almost identical in every other respect (the 0.2% is noise)
  -> but one lacks the license and one has it
  -> comparing Y across the cutoff = a locally randomized causal effect

RDD’s identifying assumption: near the cutoff, units cannot precisely manipulate their running-variable value. If banks can precisely push capital adequacy above 10.5%, RDD fails.

9.5.5 Stata Implementation: rdrobust and Bandwidth Choice ​
* -- Full RDD workflow --
use data/clean/bank_panel.dta, clear

* Suppose car = capital adequacy (running variable)
*         cutoff = 10.5
*         roe = outcome

* Install first: ssc install rdrobust

* -- Step 1: local linear regression (sharp RDD) --
rdrobust roe car, c(10.5) p(1) h(ms) kernel(triangular)
* expected output:
*   RD estimates at the cutoff (car = 10.5)
*   Coef. = 0.0342   SE = 0.0128   p = 0.008
*   95% CI: [0.0091, 0.0593]
*   read: banks clearing the threshold see ROE up by ~3.4 pp

* -- Step 2: McCrary density test (manipulation check) --
* install: ssc install rddensity
rddensity car, c(10.5)
* expected output:
*   p-value = 0.237
*   read: no significant density jump at the cutoff

* -- Step 3: graphical display --
rdplot roe car, c(10.5) p(1) nbins(20 20) ///
    title("Figure 9-4  RDD local linear regression") ///
    ytitle("ROE (%)") xtitle("Capital adequacy (%)") ///
    lineopts(lcolor(red) lwidth(medthick))
graph export "figures/rdd_robust.pdf", replace

* -- Step 4: placebo cutoffs --
rdrobust roe car, c(9.0) p(1) h(ms) kernel(triangular)
* expected: insignificant at the fake cutoff (p > 0.10)
rdrobust roe car, c(12.0) p(1) h(ms) kernel(triangular)
* expected: likewise insignificant

* -- Step 5: robustness to kernel choice --
rdrobust roe car, c(10.5) p(1) kernel(uniform)
rdrobust roe car, c(10.5) p(1) kernel(epanechnikov)
* expected: sign and significance unchanged across kernels

* Decision rule:
*   p > 0.05 -> no density jump at the cutoff -> no manipulation -> RDD valid
*   p < 0.05 -> density jump -> units may manipulate the running
*               variable -> RDD not credible

Bandwidth-choice essentials:

Table 9.22 Part B: regression discontinuity (RDD).

L4|L4|L4|L4

Bandwidth strategy & Pros & Cons & Recommendation
MSE-optimal bandwidth (default) & least mean squared error; most efficient & may be biased & ✅ main result
0.5× optimal bandwidth & less bias & few observations, high variance & robustness check
2× optimal bandwidth & more observations, precise & bias may grow & robustness check
Manually fixed bandwidth & transparent and replicable & vulnerable to “picking” & supplementary report\

9.5.6 Sharp vs Fuzzy RDD ​

Table 9.23 Type / definition / treatment probability at the cutoff / estimation method.

L5|L5|L5|L5|L5

Type & Definition & Treatment prob. at cutoff & Estimation & Finance example
Sharp RDD & crossing the cutoff → 100% treated & jumps from 0 to 1 & compare local linear fits of Y on both sides & CAR ≥ 10.5% → license granted automatically
Fuzzy RDD & crossing raises treatment probability but not to 100% & jumps from p1 to p2 (p2 > p1, < 1) & IV logic: use “above the cutoff” as an instrument for “actually treated” & loan applications scoring ≥ 60 “mostly” approved, but officers have discretion\

* -- Fuzzy RDD --
* When treatment is not uniquely determined by the cutoff,
* use rdrobust's fuzzy option: the cutoff dummy as the instrument

* Example: applications scoring >= 60 "mostly" get approved
rdrobust loan_amount credit_score, c(60) fuzzy(approved) ///
    kernel(triangular) p(1)

* Reading the output:
*   coefficient = Wald estimator
*   = (jump in Y) / (jump in treatment probability)
*   essentially 2SLS: 1(credit_score >= 60) instruments for approved
*   -> fuzzy RDD = local IV

[Takeaway] AI-assistance note: you may ask the AI “are there natural cutoffs in my data?” or “help me argue the running variable cannot be manipulated”—but the McCrary density test and bandwidth-sensitivity analyses must be run by you; AI cannot generate statistics for you (S9.4 red line).

Guided Exercise 5 ​

Task A (PSM):

  1. Open bank_panel.dta; define treat = 1 for banks with board_size above the median (large boards)

  2. Run

  3. Check whether the ATT is significant—do large boards “causally” raise ROE?

  4. Run the balance test: are post-match standardized biases below 10%?

  5. Think: can PSM rule out “unobservable management ability”? If not, which method should you use?

Task B (RDD):

  1. Suppose bank_panel.dta contains capital_ratio (capital adequacy), with the regulatory red line at 10.5%

  2. First plot the scatter: scatter roe capital_ratio || lowess roe capital_ratio

  3. Run rdplot roe capital_ratio, c(10.5) and inspect visually for a jump at the cutoff

  4. Run rdrobust roe capital_ratio, c(10.5); record the point estimate, SE, and optimal bandwidth

  5. Bandwidth sensitivity: rerun with 0.5× and 2× bandwidths; is the conclusion robust?

  6. (Advanced) Run rddensity to check for manipulation


Echoing Chapter 4’s Validity Threats ​

Among Chapter 4 §4.2’s seven internal-validity threats, the core threats PSM and RDD target:

Table 9.24 Identification strategy / Chapter 4 threat / mechanism.

L3|L3|L3

Strategy & Chapter 4 threat & Mechanism
PSM & Selection bias & “insurance participants are all risk-averse”—PSM matches on observables (income, size, education) to construct a control group equivalent on those dimensions, removing the observable part of selection bias
RDD & Selection bias—specifically “self-selection at a cutoff” & “pilot counties were the province’s favored ones”—RDD uses an exogenous cutoff in institutional rules (e.g., the capital-adequacy threshold); near the cutoff units cannot precisely manipulate their position, so the comparison is approximately randomized\

§9.6 Robustness and Heterogeneity ​

The robustness toolbox (4 tool families × 6 threats)

📐 结构图示(书版示意图的文字要点)

  1. tikzpicture
  2. Subsamples
  3. Omitted variables
  4. Reverse causality
  5. Measurement error
  6. Self-selection bias
  7. Outliers
  8. Common-method bias

Figure 9.3 Six threats × four tool families—any one threat can be pressed with several tools in combination, but you do not pick the pretty ones (see §9.6’s three-group comparison principle and the S9.2 red line).

9.6.1 The Three Robustness Groups: Main Test + Alternative Variables + Subsamples ​

After finishing the baseline regressions (§9.1–§9.5) you must answer one key question: how much does my conclusion depend on the specification? The standard practice is the “three-group comparison”:

Table 9.25 Three robustness groups: main test + alternative variables + subsamples.

L4|L4|L4|L4

Group & Meaning & Concrete operation & How to report in the paper
Group 1: main test & Change the estimator or the control set & Add more controls, change the clustering level, change the standard-error type & “After adding the XX controls, the core coefficient stays significant”
Group 2: alternative variables & Measure the core concept another way & Swap the dependent variable (ROE→ROA), swap the regressor (governance index→share of independent directors) & “After swapping the core variable, the conclusion holds in direction / does not hold”
Group 3: subsamples & Re-estimate excluding particular observations & Drop state-owned banks, drop pandemic years, keep only the eastern region & “In the subsample the effect is larger / smaller / insignificant”\

The key principle (the S9.2 red line):

  • Report all three groups faithfully, without picking the pretty ones

  • If one group fails (the core coefficient turns insignificant), write “no longer robust under XX” and discuss why

  • The purpose of robustness checks is to inform the reader, not to “pass”

* ======================================================
* §9.6 three robustness groups: main example bank_panel.dta
* ======================================================

use "data/clean/bank_panel.dta", clear
xtset bank_id year

* -- Group 1: main test (baseline + more controls + re-clustering) --
* Column (1): baseline FE, clustered at the bank level
xtreg roe governance size leverage roa cost_income i.year, fe cluster(bank_id)
est store base

* Column (2): add controls (deposit ratio dep_ratio, non-interest share nonii)
xtreg roe governance size leverage roa cost_income dep_ratio nonii i.year, fe cluster(bank_id)
est store more_ctrl

* Column (3): cluster at the province level (more conservative)
xtreg roe governance size leverage roa cost_income dep_ratio nonii i.year, fe cluster(province)
est store cluster_prov

* -- Group 2: subsample tests --
* Column (4): drop state-owned banks (state == 1)
xtreg roe governance size leverage roa cost_income dep_ratio nonii i.year if state == 0, fe cluster(province)
est store no_state

* Column (5): post-2010 sample only
xtreg roe governance size leverage roa cost_income dep_ratio nonii i.year if year >= 2010, fe cluster(province)
est store post2010

* -- Group 3: alternative dependent variable --
* Column (6): dependent variable replaced by ROA
xtreg roa governance size leverage dep_ratio nonii i.year, fe cluster(province)
est store roa_dv

* -- Combined output --
esttab base more_ctrl cluster_prov no_state post2010 roa_dv, ///
    b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) ///
    mgroups("main test" "subsample" "alt. dependent variable", ///
        pattern(1 0 1 0 1 1)) ///
    label booktabs ///
    addnotes("Notes: robust standard errors clustered at the province level in parentheses. *** p<0.01, ** p<0.05, * p<0.1.")

How to read the output:

  • If the core variable (governance) keeps the same sign and significance across all columns → the conclusion is robust

  • If one column turns insignificant → report honestly: “the effect is no longer significant after dropping state-owned banks, possibly because their governance mechanisms differ”

  • If the sign flips → a serious problem; revisit the model specification

9.6.2 The Specification Curve: A Self-Certification Tool for S9.1 “No p-hacking” ​

What is a specification curve?

Traditional robustness checks report 3–5 specifications, but a referee may object: “you picked only the specifications that favor you.” The specification-curve approach enumerates every reasonable specification (e.g., all combinations of controls), plots the distribution of the core coefficient, and lets the reader see at a glance.

The logic: if you tried 128 reasonable specifications and 120 are significant with the same sign → strong evidence. If only 20 are significant → your conclusion may be a p-hacking artifact.

* ======================================================
* Specification-curve simulation: enumerate control subsets
* ======================================================

use "data/clean/bank_panel.dta", clear
xtset bank_id year

* Define the pool of optional controls (4 variables -> 2^4 = 16 combinations)
global ctrl_pool "size leverage roa cost_income"

* Enumerate all combinations
local n_specs = 0
tempname coef_mat
postfile `coef_mat' spec_id governance_se governance_b using spec_results, replace

forvalues i = 0/15 {
    local controls ""
    local bit3 = mod(floor(`i'/8), 2)
    local bit2 = mod(floor(`i'/4), 2)
    local bit1 = mod(floor(`i'/2), 2)
    local bit0 = mod(`i', 2)
    if `bit3' == 1  local controls "`controls' size"
    if `bit2' == 1  local controls "`controls' leverage"
    if `bit1' == 1  local controls "`controls' roa"
    if `bit0' == 1  local controls "`controls' cost_income"

    capture xtreg roe governance `controls' i.year, fe cluster(province)
    if _rc == 0 {
        local n_specs = `n_specs' + 1
        post `coef_mat' (`n_specs') (_b[governance]) (_se[governance])
    }
}
postclose `coef_mat'

* Load the results and plot
preserve
use spec_results, clear
sort governance_b
gen spec_num = _n

twoway scatter governance_b spec_num, ///
    msymbol(Oh) mcolor(navy) msize(small) ///
    yline(0, lcolor(red) lpattern(dash)) ///
    title("Figure 9-5  Specification curve: 16 control combinations") ///
    note("Red line = 0. All points on the same side -> the conclusion is robust")
graph export "figures/spec_curve.pdf", replace

A word to students: the specification curve is not a device for “finding the one that is significant”; it shows that your conclusion does not hinge on one particular specification. If the curve crosses zero repeatedly, your conclusion really is fragile—and in that situation honesty matters more than significance.

9.6.3 Heterogeneity Analysis ​

Heterogeneity answers: does the core effect differ across groups? This is not “fishing for significance by another route” but exploring the boundary conditions of the effect.

Method 1: split-sample regressions (bysort)

* -- Heterogeneity: by bank type --
* bank_type: 1=large state-owned, 2=joint-stock, 3=city commercial
bysort bank_type: reghdfe roe governance size leverage, ///
    absorb(bank_id year) vce(cluster province)

* Store the group results
reghdfe roe governance size leverage if bank_type == 1, absorb(bank_id year) vce(cluster province)
est store het_soe
reghdfe roe governance size leverage if bank_type == 2, absorb(bank_id year) vce(cluster province)
est store het_joint
reghdfe roe governance size leverage if bank_type == 3, absorb(bank_id year) vce(cluster province)
est store het_city

Method 2: interaction terms

* -- Heterogeneity: interaction-term approach (preferred; allows a test of group differences) --
* Generate the interaction
gen gov_x_soe = governance * (bank_type == 1)

reghdfe roe governance gov_x_soe size leverage, ///
    absorb(bank_id year) vce(cluster province)

* How to read the output:
*   governance coefficient = baseline effect for non-state banks
*   gov_x_soe coefficient  = incremental effect for state-owned banks
*   if gov_x_soe is significant -> governance works differently for state-owned banks

Choosing between the two:

  • Split-sample regressions: intuitive and good for description; but they cannot test “whether the two coefficients differ significantly”

  • Interaction terms: test the between-group difference (via the interaction’s p value) and support inference; preferred in papers

9.6.4 Heterogeneity in the Three Side Examples ​

Table 9.26 Heterogeneity in the three side examples.

L4|L4|L4|L4

Field & Heterogeneity dimension & Grouping variable & Expected conclusion
【Finance】 capital structure & Firm size (large/medium/small) & size_group & Large firms have more financing channels; leverage is less sensitive to governance
【Insurance】 ag-insurance demand & Urban/rural (city/suburb/village) & urban_rural & Rural households are more risk averse; demand is more sensitive to subsidies
【Agriculture】 microfinance access & Region (east/central/west) & region & Financial repression is stronger in the west; relational lending matters more\

§9.7 Mediation Effects and Mechanism Tests ​

9.7.1 The Baron-Kenny Three-Step Method ​

The classic framework for testing mediation was proposed by Baron & Kenny (1986) and involves three regressions:

X -----------------------> Y          (step 1: total effect c)
X -----------------------> M          (step 2: effect of X on the mediator, a)
X ---------> M -----------> Y          (step 3: direct effect c' + mediated effect a x b)

Table 9.27 The Baron-Kenny three-step method.

L4|L4|L4|L4

Step & Regression equation & Coefficient of interest & Meaning
Step 1 & Y = α0 + c·X + controls & c & total effect of X on Y
Step 2 & M = β0 + a·X + controls & a & effect of X on the mediator M
Step 3 & Y = γ0 + c’·X + b·M + controls & c’, b & c’ = direct effect; b = effect of M on Y\

Mediated effect = a × b = c − c’

Decision rules (the stepwise procedure):

  1. Step 1: c significant → X does affect Y

  2. Step 2: a significant → X does affect M

  3. Step 3: b significant and |c′|<|c| → partial mediation

  4. If c’ is insignificant → full mediation (X affects Y entirely through M)

* ======================================================
* Baron-Kenny three steps: governance -> npl_ratio -> roe
* Hypothesis: governance raises profitability (roe) by lowering the NPL ratio
* ======================================================

use "data/clean/bank_panel.dta", clear
xtset bank_id year

* Step 1: regress Y on X (total effect c)
xtreg roe governance size leverage roa cost_income i.year, fe cluster(bank_id)
est store step1
* Expected: governance coefficient c = 0.052*** (SE = 0.018)

* Step 2: regress M on X (effect a)
xtreg npl_ratio governance size leverage roa cost_income i.year, fe cluster(bank_id)
est store step2
* Expected: governance coefficient a = -0.038*** (SE = 0.012)
* Reading: better governance -> lower NPL ratio

* Step 3: regress Y on X + M (direct effect c' + mediated effect b)
xtreg roe governance npl_ratio size leverage roa cost_income i.year, fe cluster(bank_id)
est store step3
* Expected:
*   governance coefficient c' = 0.031** (SE = 0.015) --- direct effect
*   npl_ratio coefficient b = -0.553*** (SE = 0.142)
*   mediated effect = a x b = (-0.038) x (-0.553) = 0.021
*   c'/c = 0.031/0.052 = 59.6% --- direct share of the total effect
*   mediated share = 0.021/0.052 = 40.4%

* Combined three-step table
esttab step1 step2 step3, ///
    b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) ///
    keep(governance npl_ratio) ///
    mtitles("Step1: Y~X" "Step2: M~X" "Step3: Y~X+M") ///
    title("Table 9-7  Baron-Kenny three-step mediation test") ///
    label booktabs

9.7.2 The Sobel Test ​

The Baron-Kenny stepwise procedure has one weakness: it does not directly test “whether a × b differs significantly from 0.” Sobel (1982) proposed a direct test of the mediated effect:

Sobel Z statistic: Z = a·b / SE(a·b), where SE(a·b) = a2⋅SEb2+b2⋅SEa2

Reading: |Z|>1.96 → the mediated effect is significant at the 5% level.

Limitation: the Sobel test assumes a·b is normally distributed, but a product is typically skewed → low power → Bootstrap is recommended instead.

Bootstrap does not rely on normality; it constructs the confidence interval of a·b directly by resampling:

* ======================================================
* sgmediation: one-stop mediation (Sobel + Bootstrap)
* Install: ssc install sgmediation
* ======================================================

* Method 1: sgmediation (classic three steps + Sobel test)
sgmediation roe, mv(npl_ratio) iv(governance) cv(size leverage)
* How to read the output:
*   --------------------------------------------------
*   Baron-Kenny three-step results
*   --------------------------------------------------
*   Step 1 (Y ~ X):     governance -> roe
*     c  = 0.0523 (p < 0.001)      total effect significant [check]
*
*   Step 2 (M ~ X):     governance -> npl_ratio
*     a  = -0.0381 (p < 0.001)    effect of X on M significant [check]
*
*   Step 3 (Y ~ X + M): governance + npl_ratio -> roe
*     b  = -0.5532 (p < 0.001)    effect of M on Y significant [check]
*     c' = 0.0312 (p = 0.038)      direct effect still significant -> partial mediation
*
*   Sobel test:
*     Z = a*b / SE(a*b) = 0.021 / 0.008 = 2.63
*     p = 0.009 -> mediated effect significant at the 1% level
*
*   Mediated share = a*b / c = 0.021 / 0.052 = 40.4%
*   --------------------------------------------------

* Method 2: Bootstrap mediation (preferred; no normality assumption)
capture program drop my_mediation
program define my_mediation, rclass
    syntax [anything]
    xtreg npl_ratio governance size leverage i.year, fe cluster(bank_id)
    local a = _b[governance]
    xtreg roe governance npl_ratio size leverage i.year, fe cluster(bank_id)
    local b = _b[npl_ratio]
    return scalar ind_eff = `a' * `b'
end

bootstrap r(ind_eff), reps(1000) seed(42) cluster(bank_id): my_mediation
estat bootstrap, percentile bc

Template for reporting the results (write this into the paper):

9.7.4 Path Analysis and Mediation: A Terminology Mapping ​

“In a multivariate GLM, the dependent variable of one equation is a regressor of another”—which is exactly the definition of path analysis and the essence of mediation.

The mapping:

Table 9.28 Path analysis and mediation terminology.

L3|L3|L3

Path analysis concept & Mediation terminology & Stata implementation
Exogenous variable & X (regressor) & governance
Endogenous variable (intermediate) & M (mediator) & npl_ratio
Final endogenous variable & Y (dependent variable) & roe
Direct path coefficient & c’ (direct effect) & coefficient on X in step 3
Indirect path coefficient & a × b (indirect effect) & product of the two coefficients
Total effect & c = c’ + a·b & coefficient on X in step 1\

Mediation is the simplest form of path analysis (a single indirect path). More complex multi-path models (e.g., SEM) are covered in advanced courses.

9.7.5 Mediation versus Moderation ​

Table 9.29 Mediation versus moderation.

L3|L3|L3

Dimension & Mediation & Moderation
Question answered & Through what channel does X affect Y? & Under what conditions is the effect of X on Y stronger/weaker?
Variable role & M is an intermediate link in the X→Y chain & W changes the strength/sign of the X→Y relation
Causal diagram & X → M → Y & X → Y, with W modulating the arrow’s thickness
Test & Baron-Kenny / Bootstrap & Is the interaction X×W significant (§9.6.3)
Stata command & sgmediation & reghdfe y c.x##c.w
Where in this chapter & §9.7 & §9.6.3 heterogeneity analysis\

A common confusion: heterogeneity analysis (§9.6.3) is in essence a moderation test—“the governance effect differs between state-owned and non-state banks” = “bank type moderates the governance→performance relation.”

§9.8 ABM Simulation Experiments ​

9.8.1 Why Do We Need Simulation? ​

The core capability of regression (§9.1–§9.7) is to identify causal effects from data that have already been generated, using natural experiments or statistical control. But some research questions cannot be answered by regression:

Table 9.30 Why do we need simulation?

L3|L3|L3

Limitation & Example & ABM’s solution
Cannot run an RCT & Subsidy rates cannot be randomly assigned across provinces & Simulate the counterfactual “what if the subsidy rate were 60%/70%/80%/90%” in the computer
No data exist & A new policy has not been implemented; no historical data & Simulate the likely outcomes after implementation from behavioral rules
System complexity & 500 farmers influence each other (neighborhood effects), multi-agent games & Let each agent follow decision rules and observe macro-level emergence
Nonlinear dynamics & Path dependence of participation over time (loss first then insure vs never insure) & Simulate period by period in discrete time steps and observe the dynamic trajectory\

Positioning: ABM is not a substitute for regression. Best practice is “regression + simulation” twin engines—regression verifies historical causality, simulation predicts policy effects.

9.8.2 The ODD Protocol: The International Standard for Model Description ​

Without a standardized description document an ABM cannot be reproduced by others or reviewed by referees. The ODD protocol (Grimm et al., 2006) is the internationally recognized reporting standard for ABMs:

Table 9.31 The ODD protocol: the international standard for model description.

L3|L3|L3

ODD component & Meaning & Corresponding part of the Sichuan rice-insurance ABM
Overview & Purpose, agent types, spatial structure, time scale & Evaluate subsidy-rate policy effects; 4 agent types (farmer/insurer/bank/government); small-world network; step = 1 day
Design concepts & Emergence, adaptation, objectives, learning, stochasticity & Emergent participation rate; farmers adapt via prospect theory; multiple random seeds
Details & State variables, processes, scheduling & All config.yaml parameters + annual cycle (insure→produce→disaster→harvest→claim)\

Implication for writing: if your professional-master’s thesis takes the “product design” paradigm (Appendix F.3), which includes a simulation module, then the ODD protocol is the reporting framework the “methods” section must follow.

9.8.3 The Sichuan Rice-Insurance ABM Walkthrough ​

Project path (absolute path; copy it into your own research folder before running):

/Users/xiaoshiishun/WeiyunSync(275531137)/current_work/courseware/risk_management_and_insurance_2026/sichuan_rice_insurance_abm/

Project structure:

sichuan_rice_insurance_abm/
+-- run.py                      # launcher (python run.py --scenario baseline)
+-- config.yaml                 # all parameter settings (YAML)
+-- ODD_protocol.md             # ODD-standard description document
+-- model/rice_insurance_model.py   # main model class
+-- agents/rice_farmer_agent.py     # farmer agent (core decision logic)
+-- agents/insurer_agent.py         # insurer
+-- agents/bank_agent.py            # bank (insurance + credit linkage)
+-- agents/government_agent.py      # government (subsidy policy)
+-- results/                        # run outputs

Core parameters at a glance (from config.yaml):

Table 9.32 The Sichuan rice-insurance ABM walkthrough.

L4|L4|L4|L4

Parameter class & Key parameter & Value & Data source
Model scale & number of farmers & 500 & representative sample of Sichuan’s 28 million mu of rice growers
Network structure & small-world network k=8, p=0.1 & — & proxies the rural acquaintance society
Risk preference & CRRA risk-aversion coefficient & N(1.2, 0.4) & literature estimates
Behavioral parameter & loss-aversion coefficient λ & N(2.8, 0.6) & Cai Tianming (2024), Chinese farmer experiments
Insurance contract & sum insured 1,100 yuan/mu, rate 4.5% & premium 49.5 yuan/mu & Sichuan rice full-cost insurance terms
Fiscal subsidy & total subsidy rate 75% (central 45% + provincial 20% + local 10%) & farmer pays 25% ≈ 12.4 yuan/mu & Sichuan Provincial Department of Agriculture and Rural Affairs
Disaster parameters & flood 3%/yr, drought 2%/yr, pests 5%/yr & — & NBS Sichuan Survey Office\

Walkthrough steps:

# Step 1: copy the project into your research folder
cp -r "/Users/xiaoshiishun/WeiyunSync(275531137)/current_work/courseware/risk_management_and_insurance_2026/sichuan_rice_insurance_abm/" ~/research/my_abm/

# Step 2: install dependencies
cd ~/research/my_abm
pip install -r requirements.txt

# Step 3: run the baseline scenario (subsidy rate 75%)
python run.py --scenario baseline
# observe the outputs: participation rate, fiscal spending, loss ratio

# Step 4: run the subsidy sweep (50% -> 90%, step 5%)
python run.py --scenario subsidy_sweep
# outputs four curves: subsidy rate -> participation -> fiscal efficiency -> loss ratio

The four output indicators of the subsidy_sweep parameter scan:

Table 9.33 Indicator / meaning / policy concern quick reference.

L3|L3|L3

Indicator & Meaning & Policy concern
Participation rate & share of farmers insured & policy target: ≥85%
Fiscal spending & total government subsidy & budget constraint: ≤ 80 million yuan
Fiscal efficiency & participation gain per 10,000 yuan of spending & where does the marginal benefit start declining?
Loss ratio & claims paid / premiums collected & sustainability: 60%–80% is the healthy band\

How to write it up: after running subsidy_sweep, plot the four indicators against the subsidy rate and locate the turning point where “participation ≥ 85% and fiscal efficiency is maximal” → that is your policy recommendation.

9.8.4 The Integrity Boundary of ABM ​

+-----------------------------------------------------------------------+
|  [!] Three integrity red lines for ABM simulation                     |
|                                                                       |
|  1. Simulation output != reality                                       |
|     - ABM output is "a possible outcome under the stated assumptions", |
|       not a forecast                                                   |
|     - The paper must state "the results depend on the following        |
|       assumptions: ..."                                                |
|                                                                       |
|  2. Parameter calibration and sources must be disclosed                |
|     - Every parameter needs a documented source                        |
|       (literature / statistical yearbook / survey)                     |
|     - Never set key behavioral parameters by guesswork                 |
|       (e.g., the risk-aversion coefficient)                            |
|     - The comments in config.yaml are your parameter audit trail       |
|                                                                       |
|  3. Never tune parameters to reach a desired conclusion                |
|     - Do not keep changing parameters until the output "looks right"   |
|     - Correct practice: fix parameters (with sources) -> run the model |
|       -> report the results faithfully                                 |
|     - If results contradict expectations -> discuss why, do not        |
|       change the parameters                                            |
|     - Sensitivity analysis (+/-20% perturbation) is a legitimate       |
|       robustness check                                                 |
|     - With multiple seeds (seed=42,123,456,789,999) report the mean    |
|       and standard deviation                                           |
+-----------------------------------------------------------------------+

S9.4 extension: AI can help you write Python simulation code, explain the ODD protocol, and debug errors; but AI cannot invent parameter values or fabricate simulation output for you. Every parameter must have a traceable source.

AI-Assisted Research Panel · Chapter 9 ​

Legitimate Uses of AI in Empirical Analysis ​

I ran a panel regression (reghdfe) and the output is below:

[paste the Stata output]

Please help me diagnose:
1. Any heteroskedasticity concerns? (check the Breusch-Pagan or White test p value)
2. Any multicollinearity? (check the VIF values)
3. Any endogeneity risk? (could the core regressor be correlated with the error term)
4. Is my clustering choice reasonable?

Do not make up any numbers; analyze only the output I pasted.
(2) Collaboration points for the stata-mcp six-step workflow ​

Table 9.34 Legitimate uses of AI in empirical analysis.

L3|L3|L3

Six-step stage & What AI can do & What AI must not do
Step 1 data import & Write import excel / use code for you & Invent data for you
Step 2 descriptive statistics & Generate summarize / tabstat code & Fabricate descriptive statistics
Step 3 baseline regression & Suggest specifications, write regression commands & Generate regression coefficients
Step 4 endogeneity & Brainstorm IV candidates, write ivregress code & Fabricate first-stage F statistics
Step 5 robustness & Generate the code skeleton for multiple checks & Report selectively (AI cannot know which results “look good”)
Step 6 output & Write esttab / putdocx formatting commands & Forge the numbers inside the tables\

(3) What AI can and cannot do ​

Table 9.35 What AI can do versus what AI must never do.

L2|L2

✅ AI can do & ❌ AI must never do
Generate Stata code from your description & Generate regression coefficients, standard errors, p values, R2
Explain what each statistic in the output means & Invent “plausible-looking” numbers for the paper
Diagnose possible causes of heteroskedasticity/collinearity/endogeneity & Decide for you “whether this observation should be dropped”
Recommend an identification strategy (IV/DID/PSM/RDD) & Guarantee that the recommended strategy fits your data
Write esttab / coefplot formatting code & Alter your empirical results to make them “look better”
Translate statistical jargon into plain language & Replace your own understanding of the theory\


AI Integrity Panel · Chapter 9 ​

S9.1 No p-hacking ​


+-----------------------------------------------------------------------+
| * Integrity Checkpoint S9.1                                           |
|                                                                       |
| Core principle:                                                       |
| Model specification must rest on theory, not on "which                |
| specification is most significant."                                   |
| Iron rule: "Data are for testing models, not for                      |
| specifying them."                                                     |
|                                                                       |
| Requirements:                                                         |
| [ ] Never report only the one specification that finally              |
|     turned significant after swapping three control sets              |
| [ ] Never drop "outliers" ex post to reach significance               |
|     (the dropping rule must be fixed ex ante, e.g. winsor2            |
|     run before any regression)                                        |
| [ ] Never try several dependent variables and report only             |
|     the significant one                                               |
| [ ] Never hide insignificant attempts---the specification             |
|     curve is your proof of innocence                                  |
|                                                                       |
| Self-check:                                                           |
| Draw a specification curve (S9.6.2) showing the                       |
| distribution of the core coefficient across all reasonable            |
| specifications. If the curve crosses zero repeatedly, your            |
| conclusion is not robust---and in that situation honesty              |
| matters more than significance.                                       |
|                                                                       |
| Cautionary tales:                                                     |
| - "I tried 20 control combinations; No. 17 finally gave               |
|   p<0.05"                                                             |
| - the paper reports N=387 while the raw data had N=500---             |
|   113 "outliers" were quietly deleted with no stated rule             |
| - ROE was insignificant and ROA was significant, so only              |
|   the ROA result is reported                                          |
+-----------------------------------------------------------------------+

S9.2 Report Robustness Checks Faithfully ​


+-----------------------------------------------------------------------+
| * Integrity Checkpoint S9.2                                           |
|                                                                       |
| Core principle:                                                       |
| Robustness checks give the reader complete information,               |
| not an escape route for the author.                                   |
| A "failed robustness check" must be reported just the same.           |
|                                                                       |
| Requirements:                                                         |
| [ ] Run all three groups: main test + alternative variables           |
|     + subsamples                                                      |
| [ ] Put every result into the paper's table (usually 4-6              |
|     columns)                                                          |
| [ ] If one group is insignificant, write "no longer robust            |
|     under XX" and discuss why                                         |
| [ ] Never bury an insignificant robustness check in the               |
|     appendix or a footnote                                            |
| [ ] Use a uniform phrasing: "after replacing variable X,              |
|     the core conclusion holds / no longer holds"                      |
|                                                                       |
| Self-check:                                                           |
| Check whether your robustness table shows the suspicious              |
| pattern of "stars everywhere." In reality it is normal for            |
| some robustness checks to be insignificant.                           |
|                                                                       |
| Cautionary tales:                                                     |
| - ran 10 robustness checks and put only the 4 significant             |
|   ones into the paper                                                 |
| - every column of the robustness table has p<0.01---highly            |
|   suspicious                                                          |
| - "not significant after swapping the dependent variable,"            |
|   but the paper never mentions it                                     |
+-----------------------------------------------------------------------+

S9.3 The Reproducibility Trio ​


+-----------------------------------------------------------------------+
| * Integrity Checkpoint S9.3                                           |
|                                                                       |
| Core principle:                                                       |
| Your empirical analysis must be reproducible with one                 |
| click---a classmate who receives your folder and runs                 |
| master.do gets exactly the tables in your paper.                      |
|                                                                       |
| Requirements:                                                         |
| [ ] do-file: start from use "data/raw/xxx.dta"                        |
|     - data/raw/ is a read-only archive (never modified)               |
|     - the do-file writes data/clean/ (cleaned data)                   |
|     - regressions -> tables -> figures all produced in the            |
|       do-file                                                         |
| [ ] data folder structure:                                            |
|     - data/raw/     -> raw data (read-only)                           |
|     - data/clean/   -> cleaned data (written by the do-file)          |
|     - data/derived/ -> intermediate variables (do-file)               |
| [ ] log file:                                                         |
|     - every run writes a timestamped log automatically                |
|     - the log contains all commands + output + environment            |
|       information                                                     |
|                                                                       |
| Self-check:                                                           |
| [ ] send master.do to a classmate and have them run it                |
|     from scratch                                                      |
| [ ] compare the numbers in the log with the paper's                   |
|     tables                                                            |
| [ ] confirm data/raw/ was never modified (compare MD5                 |
|     checksums)                                                        |
|                                                                       |
| Cautionary tales:                                                     |
| - "I ran that table three months ago and cannot find the              |
|   code now"                                                           |
| - data/raw/ was modified in place; the raw data can no                |
|   longer be traced                                                    |
| - the log shows N=450 but the paper says N=453                        |
+-----------------------------------------------------------------------+

S9.4 AI-Assisted Econometrics Must Not Invent Coefficients ​


+-----------------------------------------------------------------------+
| * Integrity Checkpoint S9.4                                           |
|                                                                       |
| Core principle:                                                       |
| AI is your programming assistant and interpreter, not a               |
| data generator.                                                       |
| Every number in the paper must come from your own Stata               |
| run.                                                                  |
|                                                                       |
| Requirements:                                                         |
| [ ] AI can: write code / explain output / diagnose problems           |
|     / recommend methods                                               |
| [ ] AI must never:                                                    |
|     - generate regression coefficients (e.g. "b=0.045,                |
|       se=0.012, p<0.01")                                              |
|     - fabricate F statistics, R2, Hausman p values                    |
|     - invent "plausible-looking" robustness results                   |
| [ ] red-line test: your advisor may ask you to open Stata             |
|     and reproduce any number in the paper on the spot                 |
|                                                                       |
| Self-check:                                                           |
| [ ] open your log file and check every number in the                  |
|     paper's tables                                                    |
| [ ] confirm each coefficient appears in the log                       |
| [ ] if you ever see "the suggested coefficient is..." in a            |
|     ChatGPT/AI conversation, be alarmed---that is not your            |
|     data                                                              |
|                                                                       |
| Cautionary tales:                                                     |
| - asked AI to "write a paragraph of empirical results," AI            |
|   invented the coefficients, and you pasted them in                   |
| - the advisor asks you to run the regression on the spot              |
|   and you say "I will run it and show you later"                      |
| - the numbers in the log and the paper disagree (proof the            |
|   table was typed by hand)                                            |
+-----------------------------------------------------------------------+

Deliverables of This Chapter ​

Table 9.36 Deliverables of this chapter.

L4|L4|L4|L4

# & Deliverable & Suggested filename & Notes
1 & Empirical paper draft & my_paper_v1.docx & ≥8,000 characters, with a complete empirical section
2 & Baseline regression table & & OLS/FE/RE side by side
3 & DID regression table & & main DID table + event-study figure
4 & Mediation table & & Baron-Kenny three steps + Bootstrap CI
5 & Coefficient plot & & core coefficients with 95% CIs
6 & AI-use statement & ai_disclosure_v1.md & proposal version (state where AI was involved)
7 & (elective) ABM report & abm_sweep_report.md & subsidy_sweep four-indicator results and policy advice\

Submission requirements: deliverables 1–6 are mandatory; deliverable 7 is an elective for bonus credit. All files must meet the S9.3 reproducibility-trio standard (do-file + data + log all present).


Next chapter: Chapter 9 takes the “regression route”—identifying causality from data with statistical models. But not every research question suits regression. Chapter 10 moves to the “case-study route”: when your question is How-type (“how was this policy implemented on the ground?”) or Why-type (“why did this bank fail?”), case research gives you the process insight that regression cannot. The two routes are not rivals—good professional-master’s theses are often mixed “case + data” designs.

本站教学资源仅供四川农业大学选课学生学习使用,版权归原作者所有,未经授权不得转载、转发或用于商业用途