Hi all,
I try to use a loop to regress by stock, but the loop always stops even when I use the capture command:
The loop stops with an error like this:
What's wrong with my code? I read many posts about skipping errors in the loop but couldn't find a solution.
I try to use a loop to regress by stock, but the loop always stops even when I use the capture command:
Code:
levelsof gvkey, local(groups)
foreach group of local groups{
capture reghdfe yvar xvars controlvars if gvkey==`group'
if c(rc) == 0 {
outreg2 using "G:\My Drive\research\tables\gvkey", bdec(4) tdec(2) rdec(3) adec(4) alpha(.01, .05, .10) addstat(R-squared, e(r2_a)) ctitle(`group') excel append tstat
}
else {
display as error "Unexpected error in regression"
exit `c(rc)'
}
}
Code:
G:\My Drive\research\tables/gvkey.xml dir : seeout G:\My Drive\research\tables/gvkey.xml dir : seeout G:\My Drive\research\tables/gvkey.xml dir : seeout Unexpected error in regression r(2001);

Comment