**🌟 完整工作流**:
1. **数据预处理** → 2. **共线性检验** → 3. **基准回归** → 4. **稳健性检验** → 5. **内生性处理** → 6. **异质性分析**
【咨询可联系:小菲stata 全网同名!】
**🔍 一、数据预处理(必做步骤)**
* 1. 面板声明与平衡性检查
xtset id year
xtdescribe
// 检查是否存在缺失年份
xtbalance, range(2015 2024)
// 一键生成平衡面板(需安装xtbalance)
* 2. 异常值处理
winsor2 y x1 c1 c2 c3, cuts(1 99) replace
// 上下1%缩尾
**💡 诊断工具**:
- `xtsum`查看组内/组间变异程度
- `xtline gdp if id<=10`抽查个体趋势
* 3. 描述性分析
asdoc sum y x1 c1 c2 c3
**📈 二、基础模型构建**
* 1. 控制变量筛选(VIF检验)
reg y x1 x2 c1 c2 c3
estat vif
// >10存在多重共线性
drop x2 if _vif_x2>10
// 剔除高VIF变量
* 2. 双向固定效应模型
xtreg y x1 c1 c2 c3 i.year, fe vce(cluster id)
estimates store FE
**⚠️ 关键点**:
- 行业/地区固定效应加`i.industry`或`i.region`
- 时间趋势项可加`c.year#c.x1`
**🧪 三、稳健性检验体系**
* 1. 替换核心变量
xtreg log_y x1_new c1 c2 c3 i.year, fe
// 更换代理变量
* 2. 子样本回归
xtreg y x1 c1 c2 c3 if year>=2020, fe
// 政策后时段
* 3. 动态效应检验
gen post = (year>=2020)
forvalues i=1/3 {
gen lag`i'_post = L`i'.x1 * post
}
xtreg y L(1/3).post x1 c1 c2 c3, fe
**📉 四、面板单位根与协整检验**
* 1. LLC/IPS单位根检验(需安装xtunitroot)
xtunitroot llc y, trend lags(1)
// 含趋势项
xtunitroot ips x1, demean lags(aic)
// 自动选择滞后阶
* 2. 协整检验(Kao检验)
xtcointtest kao y x1 x2, trend
// 存在趋势关系时加trend
**📚 判断标准**:
- **p<0.05** 拒绝"存在单位根"的原假设
- 若存在单位根,需做**一阶差分**:`gen dy = D.y`
**🔄 五、内生性处理**
* 1. 工具变量法
xtivreg2 y (x1 = z1) c1 c2 c3, first
// 使用z1作为x1的工具变量
* 第一阶段结果
xtreg x1 z1 c1 c2 c3 i.year, fe robust
//控制时间
est store m1
* 第二阶段结果
xtivreg2 y (x1 = z1) c1 c2 c3, fe robust first endog(x1)
est store m2
* 结果展示和导出
esttab m1 m2, replace
esttab m1 m2 using reg1.rtf, replace b(%6.3f) se(%6.3f) se ar2(3) star(* 0.1 ** 0.05 *** 0.01) compress nogap mtitles("x1" "y")title("Table1")
* 3. 面板数据的GMM估计
// 使用系统GMM方法处理内生性
xtabond2 y L.y x1 c1 c2 c3, gmm(L.y x1, collapse) iv(c1 c2 c3, eq(diff)) twostep
// Sargan检验用于过识别限制检验
// Hansen检验用于检验工具变量的有效性
// AR(2)检验用于检验误差项的二阶自相关性
**🔍 六、异质性分析**
* 1. 分组回归
xtreg y x1 c1 c2 c3 if group==1, fe
xtreg y x1 c1 c2 c3 if group==2, fe
// 针对不同组别进行回归分析
* 2. 交互项分析
gen interaction = x1 * group
xtreg y x1 interaction c1 c2 c3, fe
// 检查交互效应
**💾 七、结果输出与报告**
* 1. 三线表输出(中文显示)
esttab FE using "result.rtf", replace ///
b(%6.3f) t(%6.2f) ///
star(* 0.1 ** 0.05 *** 0.01) ///
label booktabs ///
title("固定效应回归结果") ///
addnotes("聚类标准误在个体层面,*** p<0.01")