全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
19361 7
2014-12-24
这是网上搜到的双重差分的R语言和STATA程序,因为国内比较少,分享给大家,一起学习,共同进步。网址为http://thetarzan.wordpress.com/2011/06/20/differences-in-differences-estimation-in-r-and-stata/Differences-in-Differences estimation in R and Stata{ a.k.a. Difference-in-Difference, Difference-in-Differences,DD, DID, D-I-D. }
DID estimation uses four data points to deduce the impact of a policy change or some other shock (a.k.a. treatment) on the treated population: the effect of the treatment on the treated.  The structure of the experiment implies that the treatment group and control group have similar characteristics and are trending in the same way over time.  This means that the counterfactual (unobserved scenario) is that had the treated group not received treatment, its mean value would be the same distance from the control group in the second period.  See the diagram below; the four data points are the observed mean (average) of each group. These are the only data points necessary to calculate the effect of the treatment on the treated.  The dotted lines represent the trend that is not observed by the researcher.  Notice that although the means are different, they both have the same time trend (i.e. slope).
For a more thorough work through of the effect of the Earned Income Tax Credit on female employment, see an earlier post of mine:
DID
Calculate the D-I-D Estimate of the Treatment EffectWe will now use R and Stata to calculate the unconditional difference-in-difference estimates of the effect of the 1993 EITC expansion on employment of single women.
R:# Load the foreign packagerequire(foreign)# Import data from web siterequire(foreign)# update: first download the file eitc.dta from this link:# https://docs.google.com/open?id=0B0iAUHM7ljQ1cUZvRWxjUmpfVXM# Then import from your hard drive:eitc = read.dta("C:/link/to/my/download/folder/eitc.dta")# Create two additional dummy variables to indicate before/after# and treatment/control groups.# the EITC went into effect in the year 1994eitc$post93 = as.numeric(eitc$year >= 1994)# The EITC only affects women with at least one child, so the# treatment group will be all women with children.eitc$anykids = as.numeric(eitc$children >= 1)# Compute the four data points needed in the DID calculation:a = sapply(subset(eitc, post93 == 0 & anykids == 0, select=work), mean)b = sapply(subset(eitc, post93 == 0 & anykids == 1, select=work), mean)c = sapply(subset(eitc, post93 == 1 & anykids == 0, select=work), mean)d = sapply(subset(eitc, post93 == 1 & anykids == 1, select=work), mean)# Compute the effect of the EITC on the employment of women with children:(d-c)-(b-a)The result is the width of the “shift” shown in the diagram above.
STATA:cd "C:\DATA\Econ 562\homework"use eitc, cleargen anykids = (children >= 1)gen post93 = (year >= 1994)mean work if post93==0 & anykids==0     /* value 1 */mean work if post93==0 & anykids==1     /* value 2 */mean work if post93==1 & anykids==0     /* value 3 */mean work if post93==1 & anykids==1     /* value 4 */Then you must do the calculation by hand (shown on the last line of the R code).
(value 4 – value 3) – (value 2 – value 1)




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-12-24 21:50:35
did的stata程序有
就是一般的回归模型而已
也有专门的diff命令
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-11-28 16:25:21
蓝色 发表于 2014-12-24 21:50
did的stata程序有
就是一般的回归模型而已
也有专门的diff命令
可是用diff做出来的结果好像不丰富啊,也不知道怎么解读,还请大神点拨一下
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-11-30 22:18:24
学习一下
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-12-8 13:50:56
楼主能不能发给我,愿意出50论坛币。。。因为连接打不开,急求 ,,1034169026@qq.com 非常感谢,
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-12-9 20:32:18
蓝色 发表于 2014-12-24 21:50
did的stata程序有
就是一般的回归模型而已
也有专门的diff命令
请问你那还有stata的DID命令吗?要是有的话能否传阅学习下,非常感谢。邮箱:274732712@qq.com
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群