I am conducting an event study with the market model: AR(i,t)=R(i,t) - ((alpha(i) + beta(i)*R(m,t)). I struggle with calculating the alpha(intercept) and beta(slope) estimators because of data format and filtering.
There is an "event" if the Rating Change is non-zero, what I need, is to calculate the alpha and beta for a pre-event-window of -1:-3 (example). However, there are several events per ISIN, meaning I have to group by ISIN and by the event (non-zero rating change) and then do the regression with lm() for the pre-event-window and save the values in columns next to the event and pre-event-window.
Extract of my data looks like this:
Date_ ISIN Return STOXX_Return Rating_Change Rating
2016-10-01 CH00 0.017531563 -0.0003749766 0.00 A
2016-11-01 CH00 -0.073376071 -0.0220566972 0.00 A
2016-12-01 CH00 -0.010745412 0.0182991778 0.00 A
2017-01-01 CH00 0.045742055 0.0641541456 1.90 A
2017-07-01 CH00 -0.072018814 -0.0193375447 0.00 A
2018-01-01 GB00 0.041200982 0.0144049186 0.00 B+
2018-02-01 GB00 0.040654871 0.0119439111 0.00 B+
2018-03-01 GB00 -0.029012563 -0.0463974419 0.00 B+
2018-04-01 GB00 -0.073155490 -0.0066808630 -8.90 B
2018-10-01 GB00 0.042203267 0.0047172371 0.00 B
2018-11-01 GB00 -0.073256106 -0.0545350385 0.00 B
....
What I need is another two columns, filled with alpha and beta - like this:
Date ISIN R STOXX_Return Rating_Change Rating alpha beta
2016-10-01 CH00 0.017531563 -0.0003749766 0.00 A 1 2
2016-11-01 CH00 -0.073376071 -0.0220566972 0.00 A 1 2
2016-12-01 CH00 -0.010745412 0.0182991778 0.00 A 1 2
2017-01-01 CH00 0.045742055 0.0641541456 1.90 A 1 2
2018-02-01 GB00 0.040654871 0.0119439111 0.00 B+ 3 4
2018-03-01 GB00 -0.029012563 -0.0463974419 0.00 B+ 3 4
2018-04-01 GB00 -0.073155490 -0.0066808630 -8.90 B+ 3 4
... for all Dates and ISINs
1 and 2 (3 and 4) for alpha and beta are just examples to show, for each event I need a specific alpha and beta.
I tried with for-if loops in combination with filter and lm as well as with different attempts of magrittr. However, nothing worked as I wanted probably and obviously due to the fact that I am still a beginner in R. Does anybody understand, what my issue is and how to help/solve it?
Thank you very much in advance for the support.