11808 11

[作图问题求助] DID作图如何写stata命令 [推广有奖]

  • 0关注
  • 0粉丝

学前班

90%

还不是VIP/贵宾

-

威望
0
论坛币
10 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
33 点
帖子
3
精华
0
在线时间
0 小时
注册时间
2014-9-5
最后登录
2014-9-5

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
QQ图片20140905144703.jpg

各位,我想请教一个问题。我用STATA跑出了一个DID的结果,然后想把结果画成如图所示的形式,请问命令怎么写?编码越详细越好。谢谢!
二维码

扫码加我 拉你入群

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

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

关键词:stata命令 Stata tata DID 如何写 如图所示 如何

本帖被以下文库推荐

沙发
yanwenshou 发表于 2014-9-5 15:04:40 |只看作者 |坛友微信交流群
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:



Calculate the D-I-D Estimate of the Treatment Effect
We 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:
123456789101112131415161718192021222324252627282930 # Load the foreign package require(foreign)  # Import data from web site require(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 1994 eitc$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, clear

gen 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)

Run a simple D-I-D Regression
Now we will run a regression to estimate the conditional difference-in-difference estimate of the effect of the Earned Income Tax Credit on “work”, using all women with children as the treatment group. This is exactly the same as what we did manually above, now using ordinary least squares. The regression equation is as follows:



Where  is the white noise error term, and  is the effect of the treatment on the treated — the shift shown in the diagram. To be clear, the coefficient on  is the value we are interested in (i.e., ).

R:
123 eitc$p93kids.interaction = eitc$post93*eitc$anykids reg1 = lm(work ~ post93 + anykids + p93kids.interaction, data = eitc) summary(reg1)

The coefficient estimate on p93kids.interaction should match the value calculated manually above.

STATA:
gen interaction = post93*anykids
reg work post93 anykids interaction
已有 1 人评分学术水平 热心指数 收起 理由
SpencerMeng + 1 + 1 精彩帖子

总评分: 学术水平 + 1  热心指数 + 1   查看全部评分

使用道具

藤椅
yanwenshou 发表于 2014-9-5 15:05:29 |只看作者 |坛友微信交流群
http://thetarzan.wordpress.com/2011/06/20/differences-in-differences-estimation-in-r-and-stata/

使用道具

yanwenshou 发表于 2014-9-5 15:04
Differences-in-Differences estimation in R and Stata
{ a.k.a. Difference-in-Difference, Difference- ...
没有如何作图的stata命令啊??DID的原理我知道,结果我也已经跑出来了,只是想把结果做成图。需要作图的命令。谢谢!

使用道具

报纸
voodoo 发表于 2016-5-13 09:54:16 |只看作者 |坛友微信交流群
8号光前篮球馆 发表于 2014-9-5 20:44
没有如何作图的stata命令啊??DID的原理我知道,结果我也已经跑出来了,只是想把结果做成图。需要作图的 ...
  1. twoway (scatteri 10 0 12 1, recast(connected))         ///
  2.       (scatteri 14 0 18 1, recast(connected))         ///
  3.       (scatteri 14 0 16 1, recast(connected) lpattern(".")),        ///
  4.       xtitle("Time") xlabel(0 "before" 1 "after") xscale(range(-0.2 1.2))   ///
  5.       ytitle("value") ylabel(0(5)20)   ///
  6.       legend(label(1 "Control") label(2 "Treat") label(3 "Counterfactual"))
  7. // 10 12 14 18 16等数值请自行计算啦。
复制代码

使用道具

地板
w财经w 学生认证  发表于 2017-11-28 16:14:12 |只看作者 |坛友微信交流群
voodoo 发表于 2016-5-13 09:54
你好,能解释下该命令吗?stata自带帮助文件看过,并没有您的这些选项

使用道具

7
默默磨墨11 发表于 2017-12-16 21:44:49 |只看作者 |坛友微信交流群
楼主 你的stata命令怎么写的  能告诉一下吗

使用道具

8
宝宝的杨丹丹 学生认证  发表于 2018-9-17 10:55:03 |只看作者 |坛友微信交流群
voodoo 发表于 2016-5-13 09:54
楼主你的命令跑不出来呀,只能得到三个独立的图形,怎么才能合并在一张表格上呢

使用道具

9
rangeyo 学生认证  发表于 2018-10-12 20:49:18 |只看作者 |坛友微信交流群
宝宝的杨丹丹 发表于 2018-9-17 10:55
楼主你的命令跑不出来呀,只能得到三个独立的图形,怎么才能合并在一张表格上呢
怎么画图跑出来了么

使用道具

10
超超0420 发表于 2020-4-7 22:01:54 |只看作者 |坛友微信交流群
求问图这么画,谢谢啦

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 05:49