I'm doing an event study with the evReturn
function from the erer
package.
The purpose is to get abnormal returns for each firm and average abnormal returns over all firms. I can't get the average returns because the function does a seperate execution for each firm but doesn't do one for all firms at once although this is possible with a for loop. I can't seem to get the right loop.
I've tried this method:
1.
install.packages("erer")
library(erer)
i <- 1
hh2 <- list()
for(i in 1:3){
firms <- names(dataset4)[i+1]
dates <- eventdates2[i]
print(firms)
print(dates)
print(i)
hh2[[i]] <-
evReturn(y=dataset4, firm = firms, event.date=dates, y.date="Timestamp",
index="NASDAQ", event.win = 3, est.win= 250, digits=4)
}
Example from package erer, daEsa is a dataset included in the package.
# event analysis for one firm and one event window
hhreturn <- evReturn(y = daEsa, firm = "wpp", y.date = "date",
index = "sp500", est.win = 250, digits = 3, event.date = 19990505,
event.win = 5)
# event analysis for many firms and one event window
hh2return2 <- update(hhreturn, firm = c("tin", "wy", "pcl", "pch"))
# event analysis for many firms and many event windows: need a for loop
This last comment is what I need.
Multiple dates:
hh2 <- list()
for(i in c(daEsa$date[3000], daEsa$date[3001])){
firms <- colnames(daEsa)[12:ncol(daEsa)]
print(firms)
print(i)
hh2[[i]] <-
evReturn(y=daEsa, firm = firms, event.date=i, y.date="date",
index="sp500", event.win = 2, est.win= 250, digits=4)
}
Multiple event windows (not dates):
hh2 <- list()
for(i in c(2, 3)){
firms <- colnames(daEsa)[12:ncol(daEsa)]
print(firms)
print(i)
hh2[[i]] <-
evReturn(y=daEsa, firm = firms, event.date=daEsa$date[3000], y.date="date",
index="sp500", event.win = i, est.win= 250, digits=4)
}
[1] "pch" "pcl" "pop" "tin" "wpp" "wy" [1] 2 [1] "pch" "pcl" "pop" "tin" "wpp" "wy" [1] 3