楼主: nimin
974 3

[其他] 有人会用stata的循环语句把这类型的程序改成比较简单的 [推广有奖]

  • 0关注
  • 0粉丝

小学生

50%

还不是VIP/贵宾

-

威望
0
论坛币
289 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
40 点
帖子
2
精华
0
在线时间
9 小时
注册时间
2005-12-26
最后登录
2015-9-6

100论坛币
gen post2011m5=1 if time>=tm(2011-05)
replace post2011m5=0 if time<tm(2011-05)
gen  treat_post2011m5=treat*post2011m5

gen post2011m6=1 if time>=tm(2011-06)
replace post2011m6=0 if time<tm(2011-06)
gen  treat_post2011m6=treat*post2011m6

gen post2011m7=1 if time>=tm(2011-07)
replace post2011m7=0 if time<tm(2011-07)
gen  treat_post2011m7=treat*post2011m7

gen post2011m8=1 if time>=tm(2011-08)
replace post2011m8=0 if time<tm(2011-08)
gen  treat_post2011m8=treat*post2011m8

gen post2011m9=1 if time>=tm(2011-09)
replace post2011m9=0 if time<tm(2011-09)
gen  treat_post2011m9=treat*post2011m9

gen post2011m10=1 if time>=tm(2011-10)
replace post2011m10=0 if time<tm(2011-10)
gen  treat_post2011m10=treat*post2011m10

gen post2011m11=1 if time>=tm(2011-11)
replace post2011m11=0 if time<tm(2011-11)
gen  treat_post2011m11=treat*post2011m11

gen post2011m12=1 if time>=tm(2011-12)
replace post2011m12=0 if time<tm(2011-12)
gen  treat_post2011m12=treat*post2011m12

gen post2012m1=1 if time>=tm(2012-01)
replace post2012m1=0 if time<tm(2012-01)
gen  treat_post2012m1=treat*post2012m1

gen post2012m2=1 if time>=tm(2012-02)
replace post2012m2=0 if time<tm(2012-02)
gen  treat_post2012m2=treat*post2012m2

gen post2012m3=1 if time>=tm(2012-03)
replace post2012m3=0 if time<tm(2012-03)
gen  treat_post2012m3=treat*post2012m3

这是做DID模型时的,反事实检验的一些时间设定

最佳答案

yenih 查看完整内容

------------------------------------------ clear di tm(2011-05) //616 di tm(2012-03) //623 forvalues i=616/623{ gen month`i'=`i' format month`i' %tm tostring month`i', force replace usedisplayformat local m=month`i'[1] gen post`m'=1 replace post`m'=0 if time
关键词:Stata 循环语句 tata replace place replace treat 程序
沙发
yenih 在职认证  发表于 2015-9-2 20:06:36 |只看作者 |坛友微信交流群
------------------------------------------

clear
di tm(2011-05)   //616
di tm(2012-03)  //623

forvalues i=616/623{
gen month`i'=`i'
format month`i' %tm
tostring month`i', force replace usedisplayformat
local m=month`i'[1]
gen post`m'=1
replace post`m'=0 if time<`i'
gen treat_post`m'=treat*post`m'
drop month`i'
}

--------------------------------------------
我是stata freshman一名,把这个当小练习做哈,写这个程序时有另外一个人的帮助:https://bbs.pinggu.org/thread-3882595-1-1.html


已有 1 人评分论坛币 收起 理由
giresse + 50 精彩帖子

总评分: 论坛币 + 50   查看全部评分

使用道具

藤椅
economingst 发表于 2015-9-2 22:31:28 |只看作者 |坛友微信交流群
呵呵呵呵呵呵

使用道具

板凳
winniethepaul 发表于 2015-9-3 00:52:56 |只看作者 |坛友微信交流群
啊啊啊啊啊啊啊啊啊

使用道具

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

本版微信群
加JingGuanBbs
拉您进交流群

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

GMT+8, 2024-4-25 08:40