YouMind
Sign in
MATLAB Coding Engineer

MATLAB Coding Engineer

Write, review, and debug code for research

Installed by
1
FromYouMind

Showcase

DID 双重差分分析 · MATLAB 实现

面向科研政策评估的完整 DID 工具集:双向固定效应估计、个体层聚类稳健标准误、事件研究法平行趋势检验、出版级可视化。

方案说明

基准模型为双向固定效应 DID:

$$y_{it} = \alpha_i + \lambda_t + \beta \cdot \left(\text{Treat}_i \times \text{Post}t\right) + \varepsilon{it}$$

其中 $\alpha_i$ 为个体固定效应,$\lambda_t$ 为时间固定效应,交互项系数 $\beta$ 即政策处理效应。估计上用稀疏虚拟变量承载固定效应并配合反斜杠求解,避免逐元素循环与 inv;标准误采用聚类稳健 sandwich 形式 $V = (X'X)^{-1} M (X'X)^{-1}$,其中 $M = \sum_g X_g' u_g u_g' X_g$。

平行趋势检验采用事件研究法,以政策前一期($k = -1$)为基期。若政策前的系数 $\beta_k$($k < -1$)联合不显著异于 0,则平行趋势假设成立。

文件清单

文件作用
estimateDid.mDID 主估计,返回政策效应、聚类稳健标准误、p 值、置信区间
estimateEventStudy.m事件研究法,输出动态系数与平行趋势 Wald 检验
plotDidResults.m绘制均值趋势图与事件研究系数图
buildDummyMatrix.m工具函数:分组变量转稀疏虚拟变量矩阵
computeClusterRobustVariance.m工具函数:聚类稳健方差-协方差矩阵

五个文件放在同一目录下即可直接调用。


1. estimateDid.m

<EMPTY_PARAGRAPH>

function results = estimateDid(panelTable, options)

DID 双重差分分析 · MATLAB 实现

Description

Write, review, and refactor MATLAB code based on the official MathWorks MATLAB Coding Guidelines. Automatically identify three modes—writing new code, reviewing existing code, and diagnosing errors—to produce engineering-grade code that passes Code Analyzer checks, includes Chinese comments, and provides optimization suggestions for vectorization, preallocation, and numerical robustness.

Related Skills

View all
Research

Professional Code Reviewer

Automatically validate code against plans and best practices to catch issues early and ensure a flawless delivery.

L
6650

Information

Version
v4
Last updated
Runtime credits
Usage-based
Models
Auto

Ready to create something bolder?

MATLAB Coding Engineer