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