Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • no observations r(2000) error after some observations, event study princeton

    Hi everyone,

    I am running event study using princeton example https://dss.princeton.edu/online_hel...ventstudy.html
    Everything runs correctly until the command below.
    What stata does is run the regressions for 535 companies and then the error message pops up no observations r(2000). Thus I miss regression for rest 278 companies. (In total 813 companies in my event study)
    Could you help me solve this issue?

    gen predicted_return=.
    egen id=group(company_id)
    forvalues i=1(1)813 {
    l id company_id if id==`i' & dif==0
    reg ret_price ret_index if id==`i' & estimation_window==1
    predict p if id==`i'
    replace predicted_return = p if id==`i' & event_window==1
    drop p
    }

    Thanks!
    Ola

  • #2
    So, what is happening here is that there is some id that has no observations where both ret_price and ret_index are non-missing and estimation_window == 1. The question is whether that means your data set has errors that need to be fixed, or whether this is an expected situation that you need to deal with in the code. So I would start by finding out which id's are the problems:
    Code:
    by id, sort: gen byte regress_sample_size = total(!missing(ret_price, ret_index) & estimation_window == 1)
    tab id if inlist(regress_sample_size, 0, 1)
    I have written the code to look for id's that have no usable data, or just one usable observation. I added the last condition because if you have only one usable observation, that is not enough to do a regression, and when you eventually reach one of those id's you will get another error message saying you have insufficient observations.

    Then investigate those id's to see if there should be (more) usable data for them, or not. If there should be (more) data for them, then you have to fix your data set. If it is OK for there to be no data for them, so you should just skip over them in the regressions, you can do this:

    Code:
    gen predicted_return=.
    egen id=group(company_id)
    forvalues i=1(1)813 {
        l id company_id if id==`i' & dif==0
        
        capture reg ret_price ret_index if id==`i' & estimation_window==1
        if c(rc) == 0 {    // SUCCESSFUL REGRESSION
            predict p if id==`i'
            replace predicted_return = p if id==`i' & event_window==1
            drop p
        }
        else if inlist(c(rc), 2000, 2001) { // NO OR INSUFFICIENT DATA: NOTE AND MOVE ON
            display "No or insufficient observations, i = `i'"
        }
        else {  // SOMETHING ELSE WENT WRONG.  ALERT & STOP!
            display as error "Unexpected error in regression, i = `i'"
            exit c(rc)
        }
    }
    This code will process all the id's that have sufficient data for a regression but skip over the ones that have no or insufficient data, leaving behind a message in the Results window saying that happened. In the event, however, that something other than no or insufficient data goes prevents the regression from reaching a successful conclusion, then Stata will notify you with an error message and stop.

    Comment

    Working...
    X