Hi, I would like to calculate cumulative security residual return, which is residual in a regression of a firm's monthly stock return(variable"ret") on the market monthly returns (variable "vwretd") over the 12-month period ( estimation_window) before the date of filing of the financial statement (event_window). I have prepared my data and am working on the regression loop. my codes are shown below:
gen predicted_return=.
egen id=group(company_id)
forvalues i=1(1)N { /*note: replace N with the highest value of id */
reg ret vwretd if id==`i' & estimation_window==1
predict p if id==`i'
replace predicted_return = p if id==`i' & event_window==1
drop p
}
initially, it worked well, but when it comes to id==15, it showed the following error and stopped running the loop:
(option xb assumed; fitted values)
(8,074,563 missing values generated)
(0 real changes made)
insufficient observations
(option xb assumed; fitted values)
(8,074,563 missing values generated)
(0 real changes made)
I search the forum and tried to fix the problem by using the codes below but it does work. Can I get some help?
forvalues i=1(1)N { /*note: replace N with the highest value of id */
capture noisily reg ret vwretd if id==`i' & estimation_window==1
capture noisily predict p if id==`i'
capture noisly replace predicted_return = p if id==`i' & event_window==1
capture noisly drop p
}
Related Posts with ignore insufficient observations and run the loop without breaking
using local as range in for valuesHi Statalist I would like to run a loop for every value within a variable called "spell_count", and…
Computing confidence intervals for meta-analysisHi there, I am currently attempting to run a meta-analysis on the effects of debt on economic growt…
Combining two variablesI have two variables which I want to combine together. Basically, the first variable has values like…
Retrieving values from output with missing matrix r(table)Hello to all! I'm working with some income data with the DASP package for Stata and running a calcu…
Omitted period dummies in GMM xtabond2 When reproducing this code to explain the growth relationship, it drops both period 1 and period 4…
Subscribe to:
Post Comments (Atom)
0 Response to ignore insufficient observations and run the loop without breaking
Post a Comment