全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
17772 14
2012-08-11
本人因为在做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); 不知道问题出在的哪里,请高人指点,本人感激不尽!!!
二维码

扫码加我 拉你入群

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

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

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

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

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

二维码

扫码加我 拉你入群

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

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

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
请问问题再哪呢?现在非常急,非常感谢!!!
二维码

扫码加我 拉你入群

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

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

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
二维码

扫码加我 拉你入群

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

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

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

像这样
二维码

扫码加我 拉你入群

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

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

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

假如还是不明白的话,那前面加上一句吧
su id
forvalues i = 1(1)`=r(max)'  { ...
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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