Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eventstudies package unable to handle integer dates #15

Open
mithilaas opened this issue Mar 8, 2023 · 1 comment · May be fixed by #14
Open

eventstudies package unable to handle integer dates #15

mithilaas opened this issue Mar 8, 2023 · 1 comment · May be fixed by #14

Comments

@mithilaas
Copy link

mithilaas commented Mar 8, 2023

eventstudies package accepts only "POSIXt" or "Date" format for dates and gives the following error when integers are used as index for the zoo object.

Error in phys2eventtime(z = returns$firm.returns, events = event.list[i,  : 
  events$when should be one of 'Date' or 'date-time' classes.

Here is a MWE for the issue:

library(eventstudies)
library(zoo)

### Creating data
time.dt  <- data.frame(name=c("A","B","C","D","E"),
                       when=c(3,3,3,3,3))
gdp.dt  <- data.frame(state=rep(c("A","B","C","D","E"),each=10),
                      year=rep(c(1,2,3,4,5,6,7,8,9,10),each = 1),
                      gdp= rep(c(100,100,100,160,165,50,50,50,80,85),each = 5))

dtlist <- split(gdp.dt, gdp.dt$state)

z_list <- lapply(dtlist, function(x) zoo(x$gdp, order.by = x$year))

exp.zoo  <- do.call(merge, z_list)

### eventstudy
es <- eventstudies::eventstudy(firm.returns = exp.zoo,
                 event.list = time.dt,
                 event.window = 2,
                 is.levels=FALSE,
                 type = "None",
                 to.remap = FALSE,
                 inference = TRUE)
@Toodlepoodle
Copy link

Toodlepoodle commented Mar 14, 2023

Suggested solution:
As per Anshul's PR - [WIP] Allow numeric types in phys2eventtime #14
Using Anshuls branch of eventstudy we see that the package is able to deal with integer dates.

library(zoo)
library(boot)

### Creating data
time.dt  <- data.frame(name=c("A","B","C","D","E"),
                       when=c(3,6,7,4,4))
gdp.dt  <- data.frame(state=rep(c("A","B","C","D","E"),each=10),
                      year=rep(c(1,2,3,4,5,6,7,8,9,10),each = 1),
                      gdp= rep(c(100,100,100,160,165,50,50,50,80,85),each = 5))

files.sources = list.files()
sapply(files.sources, source)

dtlist <- split(gdp.dt, gdp.dt$state)

z_list <- lapply(dtlist, function(x) zoo(x$gdp, order.by = x$year))

exp.zoo  <- do.call(merge, z_list)

### eventstudy
es <- eventstudy(firm.returns = exp.zoo,
                 event.list = time.dt,
                 event.window = 2,
                 is.levels=FALSE,
                 type = "None",
                 to.remap = FALSE,
                 inference = TRUE)

The output is as follows

2.5% Mean   97.5%
  56   76     96.000
  56   88     122.050
  56   88     122.050
  57   89     123.025

@asinghvi17 asinghvi17 linked a pull request Mar 16, 2023 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants