楼主: yuyuyuyue
17893 14

[回归分析求助] 用 stata 做event study 出现问题 [推广有奖]

  • 0关注
  • 0粉丝

初中生

38%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1992 点
帖子
6
精华
0
在线时间
20 小时
注册时间
2010-12-20
最后登录
2022-12-20

楼主
yuyuyuyue 发表于 2012-8-11 06:49:22 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
本人因为在做merger的论文,需要用stata做event study,先是用http://dss.princeton.edu/online_help/stats_packages/stata/eventstudy.html 网站上给的数据和程序模拟运行了一遍。但在做 estimating normal performance 这步开始,就运行不出来了,


官网上给的程序是:Estimating Normal Performance

set more off /* this command just keeps stata from pausing after each screen of output */gen predicted_return=.egen id=group(company_id)  /* for multiple event dates, use: egen id = group(group_id) */forvalues i=1(1)N { /*note: replace N with the highest value of id */         l id company_id if id==`i' & dif==0        reg ret market_return if id==`i' & estimation_window==1         predict p if id==`i'        replace predicted_return = p if id==`i' & event_window==1         drop p}   


我运行出来的结果是:

set more off /* this command just keeps stata from pausing after each screen of output */
varlist not allowed
r(101);.
.
.
. gen predicted_return=.
(46475 missing values generated).
. egen id=group(company_id)
id already defined
r(110);.
.  /* for multiple event dates, use: egen id = group(group_id) */
unrecognized command:  / invalid command name
r(199);.
. forvalues i=1(1)N { /*note: replace N with the highest value of id */
program error:  code follows on the same line as open brace
r(198);.
. l id company_id if id==`i' & dif==0
invalid syntax
r(198);.
. reg ret market_return if id==`i' & estimation_window==1
invalid syntax
r(198);.
. predict p if id==`i'
invalid syntax
r(198);.
. replace predicted_return = p if id==`i' & event_window==1
invalid syntax
r(198);.
. drop p.
. }
unrecognized command:  } invalid command name
r(199); 不知道问题出在的哪里,请高人指点,本人感激不尽!!!
二维码

扫码加我 拉你入群

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

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

关键词:event study Stata study Event Even multiple command normal screen 程序

沙发
voodoo 发表于 2012-8-11 13:46:54
不能在command窗口中逐句执行(遇到注释会报错),而应该用do文档方式执行。

doedit
// 将相关命令copy入do窗口中,然后选中逐一执行(快捷键ctrl+d)

// 循环体需选中程序块forvalues i = ... {...},然后执行(快捷键ctrl+d)

已有 1 人评分经验 热心指数 收起 理由
SpencerMeng + 100 + 1 观点有启发

总评分: 经验 + 100  热心指数 + 1   查看全部评分

巫毒上传,必属佳品!
坛友下载,三思后行!

藤椅
yuyuyuyue 发表于 2012-8-11 20:10:28
voodoo 发表于 2012-8-11 13:46
不能在command窗口中逐句执行(遇到注释会报错),而应该用do文档方式执行。

doedit
你好,谢谢你的回答,但是我这样做了还是有问题。
我在网上看到的原命令是这样:

set more off /* this command just keeps stata from pausing after each screen of output */

gen predicted_return=.
egen id=group(company_id)
/* for multiple event dates, use: egen id = group(group_id) */
forvalues i=1(1)N { /*note: replace N with the highest value of id */
        l id company_id if id==`i' & dif==0
        reg ret market_return if id==`i' & estimation_window==1
        predict p if id==`i'
        replace predicted_return = p if id==`i' & event_window==1
        drop p
}  

原来我就是直接贴到command 栏里,这次用了你说的方式

开始我就是先运行 doedit, 然后把这些命令在整个贴到doedit 窗口里,然后control+d 运行

doedit

. do "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\STD01000000.tmp"

. set more off /* this command just keeps stata from pausing after each screen of output */

.
. gen predicted_return=.
(46475 missing values generated)

. egen id=group(company_id)

.  /* for multiple event dates, use: egen id = group(group_id) */
. forvalues i=1(1)N { /*note: replace N with the highest value of id */
  2.         l id company_id if id==`i' & dif==0
  3.         reg ret market_return if id==`i' & estimation_window==1
  4.         predict p if id==`i'
  5.         replace predicted_return = p if id==`i' & event_window==1
  6.         drop p
  7. }  
invalid syntaxr(198);

end of do-file

但是运行结果仍然有问题

后来我又试了这样输入命令(也就是命令前面加上你写的//(虽然我不知道加这个符号是什么意思)):

// set more off /* this command just keeps stata from pausing after each screen of output */

gen predicted_return=.
egen id=group(company_id)
/* for multiple event dates, use: egen id = group(group_id) */

control+d 运行下,再:

// forvalues i=1(1)N { /*note: replace N with the highest value of id */
        l id company_id if id==`i' & dif==0
        reg ret market_return if id==`i' & estimation_window==1
        predict p if id==`i'
        replace predicted_return = p if id==`i' & event_window==1
        drop p
}  
再运行

但是这样分两次运行,程序只会运行前半部分,所以我要分别打开2个doedit 文件(把后面循环体分开)但是后面循环体 依旧说是:invalid syntax
请问问题再哪呢?现在非常急,非常感谢!!!

板凳
voodoo 发表于 2012-8-11 23:48:22
符号 // 代表注释

forvalues i = 1(1)N { /*注:用id的最大值代替N*/


总之,“磨刀不误砍柴工”,想用好Stata还是要先看些入门教材的,如《应用Stata做统计分析》https://bbs.pinggu.org/forum.php?mod=viewthread&tid=1327326&highlight=%D3%A6%D3%C3Stata
巫毒上传,必属佳品!
坛友下载,三思后行!

报纸
yuyuyuyue 发表于 2012-8-12 01:34:11
voodoo 发表于 2012-8-11 23:48
符号 // 代表注释

forvalues i = 1(1)N { /*注:最id的最大值代替N*/
谢谢!
但他总说我循环体那部分有问题
forvalues i=1(1)N { /*note: replace N with the highest value of id */
  2.         l id company_id if id==’i’ & dif==0
  3.         reg ret market_return if id==’i' & estimation_window==1
  4.         predict p if id==’i'
  5.         replace predicted_return = p if id==’i' & event_window==1
  6.         drop p
  7. }  
invalid syntaxr(198);

end of do-file

r(198);

像这样

地板
voodoo 发表于 2012-8-12 11:09:52
没错,循环体是有问题啊。答案我已经告诉你,“不能用N,而必须是变量id的最大值,自己找出来,更改N。”

假如还是不明白的话,那前面加上一句吧
su id
forvalues i = 1(1)`=r(max)'  { ...
巫毒上传,必属佳品!
坛友下载,三思后行!

7
voodoo 发表于 2012-8-12 21:09:54
和楼上内容重复啦,删除
巫毒上传,必属佳品!
坛友下载,三思后行!

8
yuyuyuyue 发表于 2012-8-12 22:35:03
voodoo 发表于 2012-8-12 21:09
当然循环体会报错了。原因我也已经说明,“不能用N,而必须用id的最大值代替N”。

假如还不明白的话,那 ...
谢谢你这么耐心的讲解,我刚运行出来了!! best wishes to you!!!! [loveliness][loveliness]

9
elearner 发表于 2012-8-13 14:22:04 来自手机
关注中

10
3生石 在职认证  发表于 2012-8-14 14:17:10
正在搞这个问题

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-29 08:54