[Eventstudies-commits] r252 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Mar 28 16:07:29 CET 2014


Author: chiraganand
Date: 2014-03-28 16:07:27 +0100 (Fri, 28 Mar 2014)
New Revision: 252

Modified:
   pkg/R/eventstudy.R
   pkg/R/phys2eventtime.R
Log:
Don't break if there are no successful outcomes, return NULL instead. Can handle univariate series now. All tests passing.

Modified: pkg/R/eventstudy.R
===================================================================
--- pkg/R/eventstudy.R	2014-03-28 13:03:55 UTC (rev 251)
+++ pkg/R/eventstudy.R	2014-03-28 15:07:27 UTC (rev 252)
@@ -69,21 +69,30 @@
   
 ### Converting index outputModel to Date
   index(outputModel) <- as.Date(index(outputModel))
-  ## Stop if there is only one firm: phys2eventtime breaks down
-  if(NCOL(outputModel)==1){stop("Event study does not work for one firm/column")}
     
 ### Convert to event frame
   es <- phys2eventtime(z=outputModel, events=eventList, width=width)
-  es.w <- window(es$z.e, start = -width, end = width)
-  ## Adding column names to event output
-  cn.names <- eventList[which(es$outcomes=="success"),1]
+
+  if (is.null(es$z.e) || length(es$z.e) == 0) {
+    es.w <- NULL
+    cn.names <- character(length = 0)
+  } else {
+    es.w <- window(es$z.e, start = -width, end = width)
+                                        # Adding column names to event output
+    cn.names <- eventList[which(es$outcomes=="success"),1]
+  }
+
   if(length(cn.names)==1){
     cat("Event date exists only for",cn.names,"\n")
     inference <- FALSE
     cat("No inference strategy for one column","\n")
+  } else if (length(cn.names) == 0) {
+    ## skip everything
+    to.remap = FALSE
+    inference = FALSE
   } else {
     colnames(es.w) <- cn.names
-  }
+  } 
   
 ### Remapping event frame
   if (to.remap == TRUE) {
@@ -124,7 +133,7 @@
 print.es <- function(x, ...){
   cat("The", x$inference, "inference output for CI and",
       colnames(x$eventstudy.output)[2], "response:", "\n")
-  return(x$eventstudy.output)
+  print.default(x$eventstudy.output)
 }
 
 summary.es <- function(object, ...){

Modified: pkg/R/phys2eventtime.R
===================================================================
--- pkg/R/phys2eventtime.R	2014-03-28 13:03:55 UTC (rev 251)
+++ pkg/R/phys2eventtime.R	2014-03-28 15:07:27 UTC (rev 252)
@@ -47,6 +47,11 @@
   rownums <- grep("outcome", names(answer))
   outcomes <- as.character(do.call("c", answer[rownums]))
   z.e <- do.call("cbind", answer[rownums[which(answer[rownums] == "success")] - 1])
+
+  if (length(z.e) == 0) {               # no point of going forward
+    return(list(z.e = z.e, outcomes = factor(outcomes)))
+  }
+
   colnames(z.e) <- which(outcomes == "success")
 
   ## Now worry about whether there's information within the event window



More information about the Eventstudies-commits mailing list