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

the argument inference = FALSE and to.remap = FALSE leads to and error in plot(eventstudy) #16

Open
Toodlepoodle opened this issue Mar 15, 2023 · 2 comments

Comments

@Toodlepoodle
Copy link

Toodlepoodle commented Mar 15, 2023

While using the eventstudy package if we put inference = FALSE it leads to an error when trying to use the plot() function within the package
Here is a MWE for the issue:

library(zoo)
library(eventstudies)

time.dt  <- data.frame(name=c("A","B"),
                       when=as.Date(c("2014-01-01","2014-01-01")))


gdp.dt  <- data.frame(state=rep(c("A","B"),each=5),
                      year=as.Date(rep(c("2012-01-01","2013-01-01","2014-01-01","2015-01-01","2016-01-01"),each = 1)),
                      gdp= c(100,100,100,160,165,50,50,50,80,85))

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 without levels,with original values
es <- eventstudies::eventstudy(firm.returns = exp.zoo,
         event.list = time.dt,
         event.window = 2,
         is.levels=FALSE,
         type = "None",
         to.remap = FALSE,
         inference = TRUE
         )
pdf("eventstudy_inference_true.pdf")
plot(es)
dev.off()
### eventstudy with levels, percentage change 
es_inf_false <- eventstudies::eventstudy(firm.returns = exp.zoo,
         event.list = time.dt,
         event.window = 2,
         is.levels=FALSE,
         type = "None",
         to.remap = FALSE,
         inference = FALSE
     )
plot(es_inf_false)

eventstudy_inference_true.pdf
The attached file is the plot created when we keep inference = TRUE
In the following case where inference = FALSE we get the following error

Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' and 'y' lengths differ

The eventstudy value in the case of inference = FALSE (i.e es_inf_false) comes out to be

     1  2
-1 100 50
0  100 50
1  160 80
2  165 85
@Toodlepoodle
Copy link
Author

While using the eventstudy package only if we put inference = FALSE and to.remap = FALSE it leads to an error when trying to use the plot() function within the package
Following is an MWE of the issue:

library(zoo)
library(eventstudies)

time.dt  <- data.frame(name=c("A","B"),
                       when=as.Date(c("2014-01-01","2014-01-01")))


gdp.dt  <- data.frame(state=rep(c("A","B"),each=5),
                      year=as.Date(rep(c("2012-01-01","2013-01-01","2014-01-01","2015-01-01","2016-01-01"),each = 1)),
                      gdp= c(100,100,100,160,165,50,50,50,80,85))

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 without levels,with original values
es <- eventstudies::eventstudy(firm.returns = exp.zoo,
         event.list = time.dt,
         event.window = 2,
         is.levels=FALSE,
         type = "None",
         to.remap = TRUE,
         inference = TRUE
         )
pdf("eventstudy_inference_true.pdf")
plot(es)
dev.off()
### eventstudy with levels, percentage change 
es_inf <- eventstudies::eventstudy(firm.returns = exp.zoo,
         event.list = time.dt,
         event.window = 2,
         is.levels=FALSE,
         type = "None",
         to.remap = TRUE,
         inference = FALSE
     )
plot(es_inf)

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

@Toodlepoodle Toodlepoodle changed the title the argument inference = FALSE leads to and error in plot(eventstudy) the argument inference = FALSE and to.remap = FALSE leads to and error in plot(eventstudy) Mar 21, 2023
@Toodlepoodle
Copy link
Author

Need to update the documentation:
While using the eventstudies package - If we put inference = FALSE and to.remap = FALSE the output we get is the just values for each unique id, at each event time. No further function is performed on the values and the mean at each event time is not calculated.This is why it leads to an error when the plot function is called.
The fact that this particular combination of arguments results in just physical date being converted to event dates and nothing else is not mentioned in the documentation.
Following is an MWE of the issue

# Loading relevant packages
library(zoo)
library(tidyverse)
library(dplyr)
library(eventstudies)

### Creating zoo object for performing eventstudy
Godda <- c(0.2194192, 0.2441143, 0.2222089, 0.2684767, 0.3066328, 0.3778628, 0.4764268, 0.6418671, 0.9171428, 1.0000000)
Durg <- c(0.9304014, 0.9425652, 0.9726595, 0.9823686, 0.8884803, 0.8591888, 0.9447556, 0.9688862, 0.9470548, 1.0000000)
Deen_Bandhu <- c(0.6331619, 0.7526251, 0.8107307, 0.7813707, 0.8360146, 0.8880688, 0.8970987, 0.9737993, 0.9030149, 1.0000000)
Panipat <- c(0.8869552, 1.0000000, 0.9307962, 0.8718149, 0.8376134, 0.8404316, 0.8766181, 0.9448039, 0.8654426, 0.8146210)
Meramandali <- c(0.8433920, 0.7743240, 0.8377193, 1.0000000, 0.6348767, 0.6395256, 0.6178923, 0.5794285, 0.5949299, 0.6380138)
# Creating the date vector
dates <- as.Date(c("2012-01-01", "2013-01-01", "2014-01-01", "2015-01-01", "2016-01-01",
                   "2017-01-01", "2018-01-01", "2019-01-01", "2020-01-01", "2021-01-01"))
# Creating the zoo object
project_radiance_zoo <- zoo(cbind(Godda, Durg, Deen_Bandhu, Panipat, Meramandali), order.by = dates)

### Creating the event date dataframe
name <- c("Godda", "Durg", "Deen_Bandhu", "Panipat", "Meramandali")
when <- c("2017-08-31", "2017-03-31", "2015-10-25", "2015-04-17", "2015-02-12")
# create the dataframe
event_date <- data.frame(name,when)
event_date$when <- as.Date(event_date$when)

### Eventstudies

# Case - I to.remap = TRUE , remap = "cumsum"  inference = TRUE
es1 <- eventstudy(firm.returns = project_radiance_zoo,
                 event.list = event_date,
                 event.window = 3,
                 type = "None",
                 to.remap = TRUE,
                 remap = "cumsum",
                 is.levels = TRUE, 
                 inference = TRUE,
                 inference.strategy = "bootstrap")

es1

# Case - II to.remap = TRUE , remap = "cumprod"  inference = TRUE
es2 <- eventstudy(firm.returns = project_radiance_zoo,
                 event.list = event_date,
                 event.window = 3,
                 type = "None",
                 to.remap = TRUE,
                 remap = "cumprod",
                 is.levels = TRUE, 
                 inference = TRUE,
                 inference.strategy = "bootstrap")

es2

# Case - III to.remap = TRUE , remap = "cumprod"  inference = FALSE
es3 <- eventstudy(firm.returns = project_radiance_zoo,
                 event.list = event_date,
                 event.window = 3,
                 type = "None",
                 to.remap = TRUE,
                 remap = "cumprod",
                 is.levels = TRUE, 
                 inference = FALSE)

es3

# Case - IV to.remap = FALSE ,  inference = TRUE
es4 <- eventstudy(firm.returns = project_radiance_zoo,
                 event.list = event_date,
                 event.window = 3,
                 type = "None",
                 to.remap = FALSE,
                 is.levels = TRUE, 
                 inference = TRUE,
                 inference.strategy = "bootstrap")

es4

# Case - V to.remap = FALSE ,  inference = FALSE
es5 <- eventstudy(firm.returns = project_radiance_zoo,
                 event.list = event_date,
                 event.window = 3,
                 type = "None",
                 to.remap = FALSE,
                 is.levels = TRUE, 
                 inference = FALSE,
                 inference.strategy = "bootstrap")

es5
plot(es5)

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

No branches or pull requests

1 participant