我目前正在与2836家公司的样本进行多项活动研究。我回顾了每个公司在几个因素上的回报(由FF编译)。因此,我写了以下循环:
gen predicted_return4=.
forvalues i = 1(1)2836 {
l id acq_company_id if id==`i' & dif==0
reg ret ${ff} if id==`i' & estimation_window==1
predict p4 if id==`i'
replace predicted_return4 = p4 if id==`i' & event_window==1
drop p4
}
循环工作得相当好。但是,经过几次回归后会出现错误(见下文)。
+---------------+
| id acq_co~d |
|---------------|
48818. | 21 8 |
+---------------+
Source | SS df MS Number of obs = 220
-------------+------------------------------ F( 3, 216) = 53.77
Model | .012074753 3 .004024918 Prob > F = 0.0000
Residual | .016167584 216 .00007485 R-squared = 0.4275
-------------+------------------------------ Adj R-squared = 0.4196
Total | .028242337 219 .00012896 Root MSE = .00865
------------------------------------------------------------------------------
ret | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
mktrf | .9786525 .119806 8.17 0.000 .7425141 1.214791
smb | .201586 .172118 1.17 0.243 -.1376599 .5408319
hml | -.1526954 .2606448 -0.59 0.559 -.6664282 .3610374
_cons | .0004081 .0005981 0.68 0.496 -.0007708 .001587
------------------------------------------------------------------------------
(option xb assumed; fitted values)
(5800880 missing values generated)
(5 real changes made)
**no observations**
r(2000);
检查数据后,我没有发现任何遗漏的观察结果。有没有人已经处理过同样的问题?有没有办法分别避免缺少值来忽略缺失值?
答案 0 :(得分:0)
如果您有足够的缺失,您将获得error 2000
。你应该想要陷阱。尝试像
gen predicted_return4=.
forvalues i = 1(1)2836 {
l id acq_company_id if id==`i' & dif==0
capture noisily reg ret ${ff} if id==`i' & estimation_window==1
quietly if _rc == 0 {
predict p4 if id==`i'
replace predicted_return4 = p4 if id==`i' & event_window==1
drop p4
}
}