Announcement

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

  • Forvalues and "no observations".

    Hi all,

    I am doing an event study with 800 different stocks and using the Princeton event study code (https://dss.princeton.edu/online_hel...ventstudy.html).

    At the time I use 'forval' the loop always stops after stock 11. Even if I remove the stock in question from the data (just to see what the problem is).

    my code:

    forval i=1/800{

    reg Ret MktRF SMB HML if Estimation_window1==1 & Id==`i'
    predict p if Id==`i'
    replace Normalreturn = p if Id==`i'
    drop p

    }

    Does anyone have a solution to make the loop continue even after the eleventh stock?

    I like to hear from you!

  • #2
    Here's one way.

    Code:
    forval i=1/800 {
    
    capture reg Ret MktRF SMB HML if Estimation_window1==1 & Id==`i'
    if _rc == 0 { 
        predict p if Id==`i'
        replace Normalreturn = p if Id==`i'
        drop p
    }
    }

    Comment


    • #3
      Dear Nick Cox,

      Thanks for your quick response!

      It works perfectly!

      You are making my day, many thanks.

      Comment

      Working...
      X