Announcement

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

  • error r(2001) - insufficient observations

    Hello all,

    I am working on a project regarding house prices, aggregated by grids and quarter, and I am trying to implement an event-study.
    I am following the guidelines from Princeton, https://dss.princeton.edu/online_hel...ventstudy.html, and wrote the following command:

    gen predicted_price=.
    egen id=group(nid)
    forvalues i=1(1)3469{
    l id nid if id==`i' & var1==0
    reghdfe norm_price x1 x2 x3 if id==`i' & estimation_window==1, a(nid quarter) vce(cluster nid quarter)
    predict p if id==`i'
    replace predicted_price = p if id==`i' & event_window==1
    drop p
    }

    When I run it, I get the error r(2001) "insufficient observations". This is very puzzling as I have a very large dateset.
    I then tried:

    gen predicted_price=.
    egen id=group(nid)
    forvalues i=1(1)3469{
    l id nid if id==`i' & var1==0
    capture reghdfe norm_price x1 x2 x3 if id==`i' & estimation_window==1, a(nid quarter) vce(cluster nid quarter)
    predict p if id==`i'
    replace predicted_price = p if id==`i' & event_window==1
    drop p
    }

    and got the error r(301) 'last estimates not found'.
    If anyone could help me, I would greatly appreciate.

    Thank you!

  • #2
    Just an update:
    I managed to solve this issue with:

    forvalues i=1(1)3469{
    l id nid if id==`i' & var1==0
    capture reghdfe norm_price x1 x2 x3 if id==`i' & estimation_window==1, resid a(nid quarter) vce(cluster nid quarter)
    if c(rc) == 0 {
    gen m1=e(rmse)
    }
    else if inlist(c(rc), 2000, 2001) {
    display "Insufficient results for i == `i': skipping to next value of i"
    continue
    }
    else {
    display "Unanticipated error in regression with i = `i'"
    exit `c(rc)'
    }
    predict p if id==`i', res
    replace predicted_price = p if id==`i' & event_window==1
    drop p
    }

    However, at some point the code stops with the error r(110) 'variable m1 already defined'.
    So this is my issue now. Thank you!

    Comment


    • #3
      It's necessary but not it seems sufficient to capture the regression if there aren't enough observations. The following commands are problematic if there was no regression. You may need something more like this:


      Code:
      gen predicted_price = .
      egen id = group(nid)
      forvalues i = 1/3469 {
          l id nid if id==`i' & var1==0
          capture {
              reghdfe norm_price x1 x2 x3 if id==`i' & estimation_window==1, a(nid quarter) vce(cluster nid quarter)
              predict p if id==`i'
              replace predicted_price = p if id==`i' & event_window==1
              drop p
          } 
      }
      Code:
      
      

      Comment


      • #4
        Dear Nick,

        Thank you for your reply. The command you suggested works. However, at the end, the variable predicted_price has no observations. Do you know what is the reason for that?

        Comment


        • #5
          Sorry, but I have no suggestions on that.

          Comment

          Working...
          X