[Eventstudies-commits] r400 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Dec 2 22:00:05 CET 2014


Author: chiraganand
Date: 2014-12-02 22:00:05 +0100 (Tue, 02 Dec 2014)
New Revision: 400

Modified:
   pkg/R/eventstudy.R
Log:
Change market returns object colname to market.returns, don't remove NA values while doing na.locf.

Modified: pkg/R/eventstudy.R
===================================================================
--- pkg/R/eventstudy.R	2014-11-30 07:24:49 UTC (rev 399)
+++ pkg/R/eventstudy.R	2014-12-02 21:00:05 UTC (rev 400)
@@ -41,6 +41,9 @@
   if (type == "lmAMM") {
 
     cat("preparing paramters\n")
+    if (length(dim(model.args$market.returns)) == 2) {
+        colnames(model.args$market.returns) <- "market.returns" # needed to fix market returns colname
+    }
     returns.zoo <- prepare.returns(event.list = event.list,
                                    event.window = event.window,
                                    list(firm.returns = firm.returns,
@@ -74,8 +77,8 @@
         args.makeX <- append(args.makeX, model.args[names.args.makeX])
 
         names.nonfirmreturns <- colnames(firm$z.e)[!colnames(firm$z.e) %in% c("firm.returns", "market.returns")]
-        args.makeX$market.returns <- na.locf(firm$z.e[estimation.period, "market.returns"]) #XXX REMOVE
-        args.makeX$others <- na.locf(firm$z.e[estimation.period, names.nonfirmreturns])
+        args.makeX$market.returns <- na.locf(firm$z.e[estimation.period, "market.returns"], na.rm = FALSE) #XXX REMOVE
+        args.makeX$others <- na.locf(firm$z.e[estimation.period, names.nonfirmreturns], na.rm = FALSE)
         regressors <- do.call(makeX, args.makeX)
 
         args.lmAMM <- list()
@@ -83,7 +86,7 @@
             args.lmAMM$nlags <- model.args$nlag.lmAMM
         }
         args.lmAMM <- append(args.lmAMM, model.args[names(model.args) %in% formalArgs(lmAMM)])
-        args.lmAMM$firm.returns <- na.locf(firm$z.e[estimation.period, "firm.returns"]) #XXX REMOVE na.locf(), its just done to get a regular residuals series.
+        args.lmAMM$firm.returns <- na.locf(firm$z.e[estimation.period, "firm.returns"], na.rm = FALSE) #XXX REMOVE na.locf(), its just done to get a regular residuals series.
         args.lmAMM$X <- regressors
 
         model <- do.call(lmAMM, args.lmAMM)
@@ -122,6 +125,9 @@
 ### marketModel
   if (type == "marketModel") {
     cat("preparing paramters\n")
+    if (length(dim(model.args$market.returns)) == 2) {
+        colnames(model.args$market.returns) <- "market.returns" # needed to fix market returns colname
+    }
     returns.zoo <- prepare.returns(event.list = event.list,
                                    event.window = event.window,
                                    list(firm.returns = firm.returns,
@@ -142,8 +148,8 @@
           return(NULL)
         }
         estimation.period <- attributes(firm)[["estimation.period"]]
-        model <- marketModel(na.locf(firm$z.e[estimation.period, "firm.returns"]), #XXX: remove na.locf
-                             na.locf(firm$z.e[estimation.period, "market.returns"]), #XXX: remove na.locf
+        model <- marketModel(na.locf(firm$z.e[estimation.period, "firm.returns"], na.rm = FALSE), #XXX: remove na.locf
+                             na.locf(firm$z.e[estimation.period, "market.returns"], na.rm = FALSE), #XXX: remove na.locf
                              residuals = FALSE)
 
           abnormal.returns <- firm$z.e[event.period, "firm.returns"] - model$coefficients["(Intercept)"] -
@@ -174,6 +180,9 @@
 ### excessReturn
   if (type == "excessReturn") {
     cat("preparing paramters\n")
+    if (length(dim(model.args$market.returns)) == 2) {
+        colnames(model.args$market.returns) <- "market.returns" # needed to fix market returns colname
+    }
     returns.zoo <- prepare.returns(event.list = event.list,
                                    event.window = event.window,
                                    list(firm.returns = firm.returns,



More information about the Eventstudies-commits mailing list