Here I am trying to do an event study where I have 32 announcement dates as event dates and sample firms returns where I got it from CRSP. The event data (event_dates) and sample firms return data (returns) looks something like this:
> str(event_dates) # check the date format
tibble [6,825 × 2] (S3: tbl_df/tbl/data.frame)
$ PERMNO : num [1:6825] 20190 20190 20190 20190 20190 ...
$ EventDate: Date[1:6825], format: "2015-05-18" "2015-09-14" "2016-02-29" "2016-02-29" ...
> str(returns) # check the date format
tibble [170,406 × 5] (S3: tbl_df/tbl/data.frame)
$ PERMNO : num [1:170406] 10853 12927 13108 13137 13168 ...
$ ReturnsDate : Date[1:170406], format: "2014-05-20" "2014-05-20" "2014-05-20" "2014-05-20" ...
$ Company Name: chr [1:170406] "RENTRAK CORP" "ZILLOW INC" "GROUPON INC" "SPDR SERIES TRUST" ...
$ Returns: num [1:170406] -0.02016 -0.03194 -0.01322 0.00133 -0.00625 ...
$ Return on the S&P 500 Index: num [1:170406] -0.0065 -0.0065 -0.0065 -0.0065 -0.0065 ...
Note: PERMNO is the company codes. I try to merge my data using.
merged_data <- event_dates %>%
mutate(start_date = EventDate - 5, end_date = EventDate + 5) %>%
left_join(returns, by = "PERMNO", relationship = "many-to-many") %>%
filter(ReturnsDate >= start_date & Date <= end_date)
My event window is -5 days to +5 days and my estimation window is -6 days to -250 days. The code is not working I know I am doing something wrong. Can you suggest a different way please.
Help with data analysis.