Announcement

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

  • Princeton's Event study did not generate the predicted return

    Hi everyone,

    I've gone through the Princeton event study stata coding, everything run through (I haven't coded the test bit), but I found that my dataset does not contain the predicted return and the accumulative return. What went wrong?

    sum predicted_ret cumulative_abnormal_return

    Variable | obs Mean Std. Dev. Min Max

    -------------+---------------------------------------------------------

    predicted_~n | 0

    cumulative~n | 8, 214 0 0 0 0




    My codes:




    gen predicted_return=.

    egen id=group(com_id)

    forvalues i=1(1)144 { /*note: replace N with the highest value of id */
    l id com\_id if id==\`i' & dif==0 reg ret mkt\_ret if id==\`i' & estimation\_window==1 predict p if id==\`i' replace predicted\_return = p if id==\`i' & event\_window3==1 drop p
    }




    *calculate abnormal return

    sort id date

    gen abnormal_return=ret-predicted_return if event_window3==1

    by id: egen cumulative_abnormal_return = total(abnormal_return)

  • #2
    I'm using stata 16 by the wat, would that affect the results?

    Comment


    • #3
      It will help if you posted a link to the code that did not work.

      Comment


      • #4
        https://dss.princeton.edu/online_hel...study.html#car
        This is the manual that i follow

        Comment


        • #5
          Just a hunch, but is this the code you tried (precisely as shown) ?

          Code:
          forvalues i=1(1)144 { /*note: replace N with the highest value of id */
          l id com\_id if id==\`i' & dif==0 reg ret mkt\_ret if id==\`i' & estimation\_window==1 predict p if id==\`i' replace predicted\_return = p if id==\`i' & event\_window3==1 drop p
          }
          If so, it will fail because you have a number of backslashes that simply confuse Stata or prevent macro substitution. And you also have multiple statements on the same line, which will also fail.

          If this was not the failure, please post back with the exact code that you ran, and the output that Stata gave, especially where the error occurred. This way you will not waste your time and the time of those who are willing to help you.

          Comment


          • #6
            Robert Picard updated the codes from that link. See #4 below and post back if you run into problems.

            https://www.statalist.org/forums/for...s-coding-issue

            Comment


            • #7
              Originally posted by Leonardo Guizzetti View Post
              Just a hunch, but is this the code you tried (precisely as shown) ?

              Code:
              forvalues i=1(1)144 { /*note: replace N with the highest value of id */
              l id com\_id if id==\`i' & dif==0 reg ret mkt\_ret if id==\`i' & estimation\_window==1 predict p if id==\`i' replace predicted\_return = p if id==\`i' & event\_window3==1 drop p
              }
              If so, it will fail because you have a number of backslashes that simply confuse Stata or prevent macro substitution. And you also have multiple statements on the same line, which will also fail.

              If this was not the failure, please post back with the exact code that you ran, and the output that Stata gave, especially where the error occurred. This way you will not waste your time and the time of those who are willing to help you.
              what is a multi-statement? is it the ones in /* ?

              Comment


              • #8
                Originally posted by Leonardo Guizzetti View Post
                Just a hunch, but is this the code you tried (precisely as shown) ?

                Code:
                forvalues i=1(1)144 { /*note: replace N with the highest value of id */
                l id com\_id if id==\`i' & dif==0 reg ret mkt\_ret if id==\`i' & estimation\_window==1 predict p if id==\`i' replace predicted\_return = p if id==\`i' & event\_window3==1 drop p
                }
                If so, it will fail because you have a number of backslashes that simply confuse Stata or prevent macro substitution. And you also have multiple statements on the same line, which will also fail.

                If this was not the failure, please post back with the exact code that you ran, and the output that Stata gave, especially where the error occurred. This way you will not waste your time and the time of those who are willing to help you.
                I've deleted the /* bit, but the code runs with no error but there is still no return.
                Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	18.6 KB
ID:	1608672

                Comment


                • #9
                  the whole code I have:
                  Code:
                  * setting up company id
                  encode epic, generate(com_id)
                  drop epic
                  drop company
                  
                  *gen sector var
                  encode sector, generate(sec_id)
                  drop sector
                  
                  *create sector dummy variable?
                  
                  * event study stata code for trading days
                  sort com_id date
                  by com_id: gen datenum=_n
                  by com_id: gen target=datenum if date==event_date
                  egen td=min(target), by (com_id)
                  drop target
                  gen dif=datenum-td
                  
                  * codes for pre/post windows, 3 day windows
                  by com_id: gen event_window3= 1 if dif>=-1 & dif<=1
                  egen count_event_obs3= count(event_window3), by(com_id)
                  
                  *estimation window
                  by com_id: gen estimation_window= 1 if dif<-6 & dif>-26
                  egen count_est_obs3=count (estimation_window), by(com_id)
                  replace event_window3=0 if event_window3==. 
                  replace event_window3=0 if estimation_window==.
                  
                  * codes for pre/post windows, 5 day windows
                  by com_id: gen event_window5= 1 if dif>=-2 & dif<=2
                  egen count_event_obs5= count(event_window5), by(com_id)
                  
                  replace event_window5=0 if event_window5==. 
                  replace event_window5=0 if estimation_window==.
                  
                  * codes for pre/post windows, 11 day windows
                  by com_id: gen event_window11= 1 if dif>=-5 & dif<=5
                  egen count_event_obs11= count(event_window11), by(com_id)
                  
                  replace event_window11=0 if event_window11==. 
                  replace event_window11=0 if estimation_window==.
                  
                  *predict return
                  gen predicted_return=.
                  egen id=group(com_id) 
                   forvalues i=1(1)144 { 
                      l id com_id if id==`i' & dif==0
                      reg ret mkt_ret if id==`i' & estimation_window==1 
                      predict p if id==`i'
                      replace predicted_return = p if id==`i' & event_window3==1 
                      drop p
                  }   
                  
                  *calculate abnormal return
                  sort id date
                  gen abnormal_return=ret-predicted_return if event_window3==1
                  by id: egen cumulative_abnormal_return = total(abnormal_return) 
                  
                  *Testing for Significance
                  sort id date
                  by id: egen ar_sd = sd(abnormal_return) 
                  gen test =(1/sqrt(3)) * ( cumulative_abnormal_return /ar_sd) 
                  list com_id cumulative_abnormal_return test if dif==0
                  
                  export excel com_id event_date cumulative_abnormal_return test using "stats.xls" if dif==0, firstrow(variables) replace

                  Comment


                  • #10
                    Originally posted by Andrew Musau View Post
                    Robert Picard updated the codes from that link. See #4 below and post back if you run into problems.

                    https://www.statalist.org/forums/for...s-coding-issue
                    I tried the code, I'm using stata 16 and it seems that

                    Code:
                     rangestat (reg) ret2use mkt_ret, interval(com_id 0 0)
                    command rangestat is unrecognized
                    r(199);
                    & if I change to
                    Code:
                    reg ret2use mkt_ret, interval(com_id 0 0)
                    option interval() not allowed
                    r(198);
                    What went wrong?

                    Comment


                    • #11
                      Code:
                      ssc install rangestat, replace

                      Comment


                      • #12
                        Originally posted by Emma Ien View Post

                        I tried the code, I'm using stata 16 and it seems that

                        Code:
                         rangestat (reg) ret2use mkt_ret, interval(com_id 0 0)
                        command rangestat is unrecognized
                        r(199);
                        & if I change to
                        Code:
                        reg ret2use mkt_ret, interval(com_id 0 0)
                        option interval() not allowed
                        r(198);
                        What went wrong?
                        I need to instal ssc

                        use code:
                        Code:
                         
                         ssc install rangestat
                        then check:

                        Code:
                         
                         help rangestat
                        to see if regenestat is usable

                        Comment


                        • #13
                          The backslashes in earlier posts arise because of cross-posting on https://www.reddit.com/r/stata/comme..._generate_the/ and of getting confused between two modes of editing allowed there. Please note our policy on cross-posting, which is that you are asked to tell us about it.

                          In #10 you must install rangestat before you can use it.

                          Code:
                          ssc install rangestat
                          As its help explains, regress does not support an option interval(). That's an option of rangestat.

                          Comment


                          • #14
                            Originally posted by Andrew Musau View Post
                            Code:
                            ssc install rangestat, replace
                            This works, thank you so much!

                            Comment


                            • #15
                              Also what codes should I add in if I also want to do an event window for

                              Code:
                              w_event = inrange(days,-1,1)
                              gen w_event = inrange(days,-5,5)
                              this is my current code
                              Code:
                              ssc install rangestat
                              
                              * setting up company id
                              encode epic, generate(com_id)
                              drop epic
                              drop company
                              
                              *gen sector var
                              encode sector, generate(sec_id)
                              drop sector
                              
                              *create sector dummy variable?
                              
                              * event study stata code for trading days
                              sort com_id date
                              by com_id: gen tradeday = _n
                              by com_id: gen event_obs = event_date == date
                              bysort com_id (event_obs): gen days = tradeday - tradeday[_N] if event_date[_N] == date[_N]
                              
                              gen w_event = inrange(days,-1,1)
                              gen w_estim = inrange(days,-26,-6)
                              by com_id: egen N_w_event = total(w_event)
                              by com_id: egen N_w_estim = total(w_estim)
                              
                              drop if N_w_event < 3
                              drop if N_w_estim < 20
                              
                              * Estimating Normal Performance
                              gen ret2use = ret if w_estim
                              rangestat (reg) ret2use mkt_ret, interval(com_id 0 0)
                              gen p_return = b_mkt_ret * mkt_ret + b_cons if w_event
                              
                              * Abnormal and Cumulative Abnormal Returns
                              gen abnormal_return = ret - p_return
                              by com_id: egen cumulative_abnormal_return = total(abnormal_return)
                              
                              * Testing for Significance
                              by com_id: egen ar_sd = sd(abnormal_return) 
                              gen test =(1/sqrt(N_w_event)) * ///
                                  (cumulative_abnormal_return /ar_sd) 
                              
                              * Testing Across All Events
                              reg cumulative_abnormal_return if days==0

                              Comment

                              Working...
                              X