Announcement

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

  • Generating a variable that displays an event time at the maximum value

    Hi everybody,

    I am working on a dataset about abnormal stock returns following earnings announcements. Per firm and event date, the abnormal returns for 20 days before and 30 days after the announcement are listed.
    I have created the variable that denotes that maximum value of the abnormal return per firm and event date. I am having trouble generating a variable that denotes on which day that maximum value occurred.

    For example, for American Airlines and the announcement date 24 july 2014, I can manually see that the maximum abnormal return occurred 2 days after the announcement and the minimum abornal return occurred 12 days before the announcement.

    Could somebody please help me generate a variable that will couple 2 to the maximum abnormal return and -12 to the minimum abnormal return for all firms and event dates?
    Would be a great help and thanks in advance!

    Regards,
    Tim

  • #2
    Tim:
    welcome to this forum.
    As usual, FAQ rule here: please procide an example/excerpt of your dataset via -dataex-. Thanks.
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      As Carlo Lazzaro notes, we request data examples whenever that would help, as it usually does.

      Here you don't give any of your variable names, so the example here needs to be translated to your set-up.

      The issue of when a maximum or minimum occurs is tricky whenever a maximum or minimum occurs twice or more (there are ties) within a window, which is probably not an issue for you, but other readers should watch out. Here I ride roughshod over the issue by picking the first date that either extreme occurs. That may or may not be what is needed.

      I used rangerun from SSC and no doubt there are other ways to do it, but the other ways would need to cope with the fact that data windows here overlap.

      Subtraction say year - whenmax or year - whenmin should seem trivial if that is what you want.

      Code:
      webuse grunfeld, clear
      
      capture program drop mycalc
      
      program mycalc
         su invest, meanonly
         gen min = r(min)
         gen max = r(max)
         su year if invest == min, meanonly
         gen whenmin = r(min)
         su year if invest == max, meanonly
         gen whenmax = r(min)
      end
      
      rangerun mycalc, use(invest year) interval(year -3 3) by(company)
      
      
      list year invest *min *max if company == 1
      
           +----------------------------------------------------+
           | year   invest     min   whenmin      max   whenmax |
           |----------------------------------------------------|
        1. | 1935    317.6   257.7      1938    410.6      1937 |
        2. | 1936    391.8   257.7      1938    410.6      1937 |
        3. | 1937    410.6   257.7      1938    461.2      1940 |
        4. | 1938    257.7   257.7      1938      512      1941 |
        5. | 1939    330.8   257.7      1938      512      1941 |
           |----------------------------------------------------|
        6. | 1940    461.2   257.7      1938      512      1941 |
        7. | 1941      512   257.7      1938    547.5      1944 |
        8. | 1942      448   330.8      1939    561.2      1945 |
        9. | 1943    499.6     448      1942    688.1      1946 |
       10. | 1944    547.5     448      1942    688.1      1946 |
           |----------------------------------------------------|
       11. | 1945    561.2     448      1942    688.1      1946 |
       12. | 1946    688.1   499.6      1943    688.1      1946 |
       13. | 1947    568.9   529.2      1948    688.1      1946 |
       14. | 1948    529.2   529.2      1948    755.9      1951 |
       15. | 1949    555.1   529.2      1948    891.2      1952 |
           |----------------------------------------------------|
       16. | 1950    642.9   529.2      1948   1304.4      1953 |
       17. | 1951    755.9   529.2      1948   1486.7      1954 |
       18. | 1952    891.2   555.1      1949   1486.7      1954 |
       19. | 1953   1304.4   642.9      1950   1486.7      1954 |
       20. | 1954   1486.7   755.9      1951   1486.7      1954 |
           +----------------------------------------------------+
      Last edited by Nick Cox; 04 Dec 2022, 05:55.

      Comment


      • #4
        Hi Nick,

        Thanks for your response, very helpful already. Below is an example of my data:

        ticker evttime abret
        "DELL" 24 -.02428361591262118
        "DELL" 17 .0033394506516187493
        "DELL" 4 .009579618224944164
        "DELL" -15 .033299316586129724
        "DELL" -8 .014468903398140016
        "DELL" 29 -.02793519443345241
        "DELL" 10 -.015030342919379654
        "DELL" 0 .08413072062215177
        "DELL" -16 .005063471510325026
        "DELL" 9 .023728832224147196
        "DELL" 25 .018748586338185595
        "DELL" 15 .0026855643435739485
        "DELL" 8 .02479737267457715
        "DELL" -13 -.02082837932385369
        "DELL" 18 .01777126222837215
        "DELL" 7 -.007819523711140954
        "DELL" 1 -.030046066361011488
        "DELL" 2 -.014924279760957249
        "DELL" 3 .031152200601304754
        "DELL" 5 .06515818134512466
        "DELL" -4 .00024300119042424843
        "DELL" -6 -.02301550915044779
        "DELL" 12 -.027222502703150697
        "DELL" 30 -.020057535406585537
        "DELL" -12 .0076266564542331414
        "DELL" -9 .023471674844626117
        "DELL" -20 -.01582556095267789
        "DELL" -17 -.04139935238438555
        "DELL" -5 -.007460332894125572
        "DELL" 20 .020679950599408616
        "DELL" 11 -.015042873334545319
        "DELL" 22 .047899921009160476
        "DELL" -10 -.06497464449940747
        "DELL" -11 -.03685822831331319
        "DELL" 19 .04633719323901661
        "DELL" 6 .01494956038892174
        "DELL" 16 .019254051068587685
        "DELL" -7 -.002010424581422041
        "DELL" -2 -.029285367587000153
        "DELL" 26 .04129750228268581
        "DELL" 28 -.013091166369898285
        "DELL" 27 -.01711832162152064
        "DELL" 13 .03782414812294015
        "DELL" 21 .08482227144901913
        "DELL" 14 .04537710160008009
        "DELL" -18 .0068657915923278755
        "DELL" -1 -.019956362132873145
        "DELL" 23 -.050002977275052964
        "DELL" -14 -.0029459805672995445
        "DELL" -3 -.027039960439493693
        "DELL" -19 .0129548137117707

        The goal is to obtain a new variable 'whenmax' that would indicate per firm per eventdate which day the maximum value was achieved. The varialbe would then denote for example 12, 51 times for each event time of this event date. Hopefully you could help me with this specific example as it is the last piece of the puzzle to obtain the final version of my dataset.

        Would be a great help and thanks in advance!

        Comment


        • #5
          I don't think I understand your set-up well enough to modify my code, so I think you need to study my example to do that.

          Comment


          • #6
            Perhaps I am also not fully understanding your issue, but my impression is that all you need is:

            Code:
            bysort ticker (abret): gen whenmax = evttime[_N]
            where you probably need to add a variable that denotes the event/eventdate into the bysort prefix (there was nothing for that in your data example, so I couldn't add it in).

            Comment

            Working...
            X