2023年3月27日,计量经济学服务中心&数量经济学2023年因果推断专题讲座之DID专题讲座第一课于19:00-21:200顺利开讲。 往期部分Stata寒暑假班课程学员(2017--2023年)通过相关报名,参加了我们的讲座,下面就讲座内容做一介绍。 首先我们先来看下讲座大纲目录: 一、DID专题讲座内容1、简介/引言/理论部分 2、DID资源/推文 3、传统DID模型估计命令及交叠DID估计命令 4、DID模型 - 1、交错双重差分法 (staggered DiD)
- 2、广义双重差分法 (generalized DiD)
- 5、三重差分法 (triple differences)
5、传统DID专题 6、多期DID/渐进DID 7、PSM-DID、PSM-DDD 8、交叠DID 9、DID异质处理效应估计量
DID专题讲座第一课于3月27日(周一)19:00一直持续到21:20分,主要讲解了DID理论知识及操作应用。 双重差分法(Difference-In-Difference, DID)由于其清晰直观 ,易于操作,并且实际操作难度较低,上手简单等特点而广为应用,目前已经成为应用最广的因果推断方法(几乎没有之一),在政策评估中受到国内外学者青睐。 双重差分法,又称为倍分法,倍差法,或者差异中差异,用DID或者DD来表示。目前DID模型有很多类,可以分为标准DID,多期DID,交错DID,广义DID,队列双重差分法、模糊双重差分法、混合截面DID、PSM-DID、PSM-DDD以及其他双重差分法。 讲座从180多年前的约翰--斯诺的霍乱假说讲起,引入了DID双重差分的一个设计,同时为大家介绍了因果推断中的基础理论知识,包括随机实验以及自然实验,因果推断的基本前提假设,通过SUVTA以及前侧后侧事实比较等引入DID模型设计。 本次讲座主要为大家介绍了单一时点DID以及多时点DID的区别,同时针对传统的DID模型,讲解了最低工资法案的具体应用,最后通过普林斯顿大学Panel101数据为例,为大家介绍了传统DID模型中的7个常见命令的具体操作应用。 一图读懂:7个常规DID命令+13个最新DID命令 据悉DID专题讲座第2课也将于今晚3月29日(周三)19:00-21:00再次开讲,后续DID专题讲座新增课程也将近期通知。 面向往期学员推出SCM专题讲座也将于近期开讲,敬请请关注。 本次讲座部分板书截图如下,你也可以通过本文后面提供的文档进行操作学习。 ![图片](http://image109.360doc.com/DownloadImg/2023/03/2919/263380464_1_20230329074610972.png)
![图片](http://image109.360doc.com/DownloadImg/2023/03/2919/263380464_2_2023032907461197.png)
![图片](http://image109.360doc.com/DownloadImg/2023/03/2919/263380464_3_20230329074611222.png)
![图片](http://image109.360doc.com/DownloadImg/2023/03/2919/263380464_4_20230329074611362.png)
![图片](http://image109.360doc.com/DownloadImg/2023/03/2919/263380464_5_20230329074611487.png)
![图片](http://image109.360doc.com/DownloadImg/2023/03/2919/263380464_6_20230329074611628.png)
![图片](http://image109.360doc.com/DownloadImg/2023/03/2919/263380464_7_20230329074611722.png)
![图片](http://image109.360doc.com/DownloadImg/2023/03/2919/263380464_8_20230329074611847.png)
![图片](http://image109.360doc.com/DownloadImg/2023/03/2919/263380464_9_20230329074611972.png)
![图片](http://image109.360doc.com/DownloadImg/2023/03/2919/263380464_10_20230329074612144.png)
![图片](http://pubimage.360doc.com/wz/default.gif)
![图片](http://pubimage.360doc.com/wz/default.gif)
![图片](http://pubimage.360doc.com/wz/default.gif)
![图片](http://pubimage.360doc.com/wz/default.gif)
![图片](http://pubimage.360doc.com/wz/default.gif)
![图片](http://pubimage.360doc.com/wz/default.gif)
![图片](http://pubimage.360doc.com/wz/default.gif)
![图片](http://pubimage.360doc.com/wz/default.gif)
1、路径设置 *------------------------------------------------------------------------------- . *-定义工作路径等常规设置 . global path 'E:\2023年3月DID专题讲座\Stata-202303\A17-diff'
. global D '$path\data' // 范例数据
. global R '$path\refs' // 参考文献
. global Out '$path\Out' // 结果:图形和表格
. adopath + '$path\adofiles' // 外部命令
. cd '$D'
*------------------------------------------------------------------------------- .
2、导入数据查看数据. use 'Panel101.dta', clear
.
. ed
. desc
Contains data from Panel101.dta Observations: 70 Variables: 9 3 Jan 2020 11:28 ---------------------------------------------------------------------------------------------- Variable Storage Display Value name type format label Variable label ---------------------------------------------------------------------------------------------- country long %14.0g country Country year int %8.0g Year y double %10.0g Outcome Y y_bin float %9.0g Binary outcome Y x1 float %9.0g Predictor x1 x2 float %9.0g Predictor x2 x3 float %9.0g Predictor x3 opinion float %18.0g agree Categorical variable op float %9.0g ---------------------------------------------------------------------------------------------- Sorted by: country year
3、DID模型变量设置. * Create a dummy variable to indicate the time when the treatment started. . * Lets assume that treatment started in 1994. . * In this case, years before 1994 will have a value of 0 and 1994+ a 1. . * If you already have this skip this step.设置虚拟变量,政策执行时间为1994年 . gen time = (year>=1994) & !missing(year)
. . * Create a dummy variable to identify the group exposed to the treatment. . * In this example lets assumed that countries with code 5,6, and 7 were treated (=1). . * Countries 1-4 were not treated (=0). If you already have this skip this step生成地区的 > 虚拟变量 . gen treated = (country>4) & !missing(country)
. . * Create an interaction between time and treated. We will call this interaction `did' 产 > 生交互项 . gen did = time*treated
4、第1个命令传统reg估计. . * Estimating the DID estimator随后将这三个变量作为解释变量,y作为被解释变量进行回归: . reg y time treated did, r
Linear regression Number of obs = 70 F(3, 66) = 2.17 Prob > F = 0.0998 R-squared = 0.0827 Root MSE = 3.0e+09
------------------------------------------------------------------------------ | Robust y | Coefficient std. err. t P>|t| [95% conf. interval] -------------+---------------------------------------------------------------- time | 2.29e+09 9.00e+08 2.54 0.013 4.92e+08 4.09e+09 treated | 1.78e+09 1.05e+09 1.70 0.094 -3.11e+08 3.86e+09 did | -2.52e+09 1.45e+09 -1.73 0.088 -5.42e+09 3.81e+08 _cons | 3.58e+08 7.61e+08 0.47 0.640 -1.16e+09 1.88e+09 ------------------------------------------------------------------------------
. est store ols
. end of do-file
. reg y time##treated, r
Linear regression Number of obs = 70 F(3, 66) = 2.17 Prob > F = 0.0998 R-squared = 0.0827 Root MSE = 3.0e+09
------------------------------------------------------------------------------ | Robust y | Coefficient std. err. t P>|t| [95% conf. interval] -------------+---------------------------------------------------------------- 1.time | 2.29e+09 9.00e+08 2.54 0.013 4.92e+08 4.09e+09 1.treated | 1.78e+09 1.05e+09 1.70 0.094 -3.11e+08 3.86e+09 | time#treated | 1 1 | -2.52e+09 1.45e+09 -1.73 0.088 -5.42e+09 3.81e+08 | _cons | 3.58e+08 7.61e+08 0.47 0.640 -1.16e+09 1.88e+09 ------------------------------------------------------------------------------
5、第2个命令diff操作. diff y, t(treated) p(time)
DIFFERENCE-IN-DIFFERENCES ESTIMATION RESULTS Number of observations in the DIFF-IN-DIFF: 70 Before After Control: 16 24 40 Treated: 12 18 30 28 42 -------------------------------------------------------- Outcome var. | y | S. Err. | |t| | P>|t| ----------------+---------+---------+---------+--------- Before | | | | Control | 3.6e+08| | | Treated | 2.1e+09| | | Diff (T-C) | 1.8e+09| 1.1e+09| 1.58 | 0.120 After | | | | Control | 2.6e+09| | | Treated | 1.9e+09| | | Diff (T-C) | -7.4e+08| 9.2e+08| 0.81 | 0.422 | | | | Diff-in-Diff | -2.5e+09| 1.5e+09| 1.73 | 0.088* -------------------------------------------------------- R-square: 0.08 * Means and Standard Errors are estimated by linear regression **Inference: *** p<0.01; ** p<0.05; * p<0.1
. end of do-file
. do 'C:\Users\Metrics\AppData\Local\Temp\STD3ac0_000000.tmp'
. diff y, t(treated) p(time)
DIFFERENCE-IN-DIFFERENCES ESTIMATION RESULTS Number of observations in the DIFF-IN-DIFF: 70 Before After Control: 16 24 40 Treated: 12 18 30 28 42 -------------------------------------------------------- Outcome var. | y | S. Err. | |t| | P>|t| ----------------+---------+---------+---------+--------- Before | | | | Control | 3.6e+08| | | Treated | 2.1e+09| | | Diff (T-C) | 1.8e+09| 1.1e+09| 1.58 | 0.120 After | | | | Control | 2.6e+09| | | Treated | 1.9e+09| | | Diff (T-C) | -7.4e+08| 9.2e+08| 0.81 | 0.422 | | | | Diff-in-Diff | -2.5e+09| 1.5e+09| 1.73 | 0.088* -------------------------------------------------------- R-square: 0.08 * Means and Standard Errors are estimated by linear regression **Inference: *** p<0.01; ** p<0.05; * p<0.1
. est store diff
6、第3个命令xtreg. xtset country year
Panel variable: country (strongly balanced) Time variable: year, 1990 to 1999 Delta: 1 unit
. xtreg y did i.year,r fe
Fixed-effects (within) regression Number of obs = 70 Group variable: country Number of groups = 7
R-squared: Obs per group: Within = 0.2661 min = 10 Between = 0.0116 avg = 10.0 Overall = 0.1568 max = 10
F(6,6) = . corr(u_i, Xb) = -0.2753 Prob > F = .
(Std. err. adjusted for 7 clusters in country) ------------------------------------------------------------------------------ | Robust y | Coefficient std. err. t P>|t| [95% conf. interval] -------------+---------------------------------------------------------------- did | -2.52e+09 1.09e+09 -2.32 0.059 -5.18e+09 1.38e+08 | year | 1991 | 6.17e+08 1.41e+09 0.44 0.676 -2.82e+09 4.06e+09 1992 | 6.47e+08 8.04e+08 0.80 0.452 -1.32e+09 2.61e+09 1993 | 3.20e+09 1.56e+09 2.05 0.086 -6.10e+08 7.01e+09 1994 | 4.74e+09 1.66e+09 2.85 0.029 6.76e+08 8.80e+09 1995 | 2.62e+09 1.90e+09 1.38 0.218 -2.04e+09 7.28e+09 1996 | 3.49e+09 1.06e+09 3.29 0.017 8.94e+08 6.09e+09 1997 | 4.80e+09 1.14e+09 4.22 0.006 2.02e+09 7.58e+09 1998 | 2.07e+09 1.31e+09 1.58 0.164 -1.13e+09 5.28e+09 1999 | 2.70e+09 1.96e+09 1.38 0.216 -2.08e+09 7.49e+09 | _cons | 3871104 7.97e+08 0.00 0.996 -1.95e+09 1.96e+09 -------------+---------------------------------------------------------------- sigma_u | 1.615e+09 sigma_e | 2.693e+09 rho | .26458903 (fraction of variance due to u_i) ------------------------------------------------------------------------------
. est sto xtreg
7、第4个命令areg. areg y did i.year ,absorb(country ) r
Linear regression, absorbing indicators Number of obs = 70 Absorbed variable: country No. of categories = 7 F(10, 53) = 3.87 Prob > F = 0.0006 R-squared = 0.3874 Adj R-squared = 0.2024 Root MSE = 2.693e+09
------------------------------------------------------------------------------ | Robust y | Coefficient std. err. t P>|t| [95% conf. interval] -------------+---------------------------------------------------------------- did | -2.52e+09 1.29e+09 -1.96 0.055 -5.10e+09 5.91e+07 | year | 1991 | 6.17e+08 1.33e+09 0.46 0.644 -2.05e+09 3.28e+09 1992 | 6.47e+08 8.73e+08 0.74 0.462 -1.10e+09 2.40e+09 1993 | 3.20e+09 1.20e+09 2.67 0.010 7.92e+08 5.60e+09 1994 | 4.74e+09 1.23e+09 3.84 0.000 2.26e+09 7.21e+09 1995 | 2.62e+09 1.83e+09 1.43 0.158 -1.05e+09 6.29e+09 1996 | 3.49e+09 1.18e+09 2.96 0.005 1.13e+09 5.86e+09 1997 | 4.80e+09 1.16e+09 4.15 0.000 2.48e+09 7.12e+09 1998 | 2.07e+09 1.55e+09 1.33 0.188 -1.04e+09 5.19e+09 1999 | 2.70e+09 1.75e+09 1.54 0.129 -8.15e+08 6.22e+09 | _cons | 3871104 7.85e+08 0.00 0.996 -1.57e+09 1.58e+09 ------------------------------------------------------------------------------
. est sto areg
. end of do-file
8、第5个命令reghdfe. . reghdfe y did,absorb(country year ) (MWFE estimator converged in 2 iterations)
HDFE Linear regression Number of obs = 70 Absorbing 2 HDFE groups F( 1, 53) = 3.60 Prob > F = 0.0632 R-squared = 0.3874 Adj R-squared = 0.2024 Within R-sq. = 0.0636 Root MSE = 2.693e+09
------------------------------------------------------------------------------ y | Coefficient Std. err. t P>|t| [95% conf. interval] -------------+---------------------------------------------------------------- did | -2.52e+09 1.33e+09 -1.90 0.063 -5.18e+09 1.43e+08 _cons | 2.49e+09 4.69e+08 5.31 0.000 1.55e+09 3.43e+09 ------------------------------------------------------------------------------
Absorbed degrees of freedom: -----------------------------------------------------+ Absorbed FE | Categories - Redundant = Num. Coefs | -------------+---------------------------------------| country | 7 0 7 | year | 10 1 9 | -----------------------------------------------------+
.
9、其他2个命令:didregress+ xtdidregressDID最新应用必读文章: 2023年第3期《数量经济技术经济研究》目录及计量方法汇总表(DID、DDD等) 《数量经济技术经济研究》上2篇最新DID论文:交错DID及小样本双重差分RI-DID DID前沿论文推荐 |《中国工业经济》:交错DID及异质性—稳健DID(附代码实现) csdid2:多时期DID的异质性稳健估计量 一图读懂:7个常规DID命令+13个最新DID命令 推荐:《中国工业经济》2023年第2期-稳健DID估计量+Goodman Bacon分解 permute:DID安慰剂检验随机抽样500/1000次--2023年《中国工业经济》最新应用 2023新版_DID进展汇总:命令、书单、论文、文章资源汇总 理解DID出了什么问题?双向固定效应模型TWFE与异质性处理效应drdid和csdid DRDID--双重稳健估计量 Bacon分解bacondecomp新+旧版本操作及ddtiming命令(三合一)操作应用 免费公开课:交叠DID偏误及Bacon分解+案例应用 微观计量最新进展及最新DID规范动作、文献、命令等资源推荐 资源推荐:直接动态展示培根分解、事件研究和交错处理、断点回归、随机化推理 csdid:多时期DID的异质性稳健估计量 理解DID出了什么问题?双向固定效应模型TWFE与异质性处理效应drdid和csdid 书籍推荐:《因果推断:混音带》(内涵高级DID、合成控制法、机器学习和因果推理等资源课件) 双重差分法(DID)平行趋势及安慰剂检验方法案例合集 csdid:多时期DID的异质性稳健估计量 综合控制、合成DID最新书单、命令包汇总 微观计量最新进展及最新DID规范动作、文献、命令等资源推荐
|