[Eventstudies-commits] r397 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Nov 28 11:38:32 CET 2014


Author: chiraganand
Date: 2014-11-28 11:38:32 +0100 (Fri, 28 Nov 2014)
New Revision: 397

Modified:
   pkg/R/marketModel.R
Log:
Merge firm returns and market returns before calling lm, removing it had caused a bug where lm wouldn't return a proper zoo object in the residuals series.

Modified: pkg/R/marketModel.R
===================================================================
--- pkg/R/marketModel.R	2014-11-24 06:24:18 UTC (rev 396)
+++ pkg/R/marketModel.R	2014-11-28 10:38:32 UTC (rev 397)
@@ -3,7 +3,8 @@
 
                                         # Single firm
     if (NCOL(firm.returns) == 1) {
-        reg <- lm(firm.returns ~ market.returns,
+        merged.object <- merge.zoo(firm.returns, market.returns, all = TRUE) #:DOC
+        reg <- lm(firm.returns ~ market.returns, data = merged.object,
                   na.action = na.exclude) # :DOC: na.exclude: NAs can
                                           # be seen in prediction
 
@@ -22,7 +23,9 @@
         ## does na.omit, thereby removing rows from some firms even if
         ## they don't have NAs in them.
         for (i in 1:NCOL(firm.returns)) {
-            reg[[i]] <- lm(firm.returns[, i] ~ market.returns,
+            merged.object <- merge.zoo(firm.returns[, i], market.returns, all = TRUE)
+            colnames(merged.object)[i] <- "firm.returns"
+            reg[[i]] <- lm(firm.returns ~ market.returns, data = merged.object,
                            na.action = na.exclude)
 
             if (residuals == TRUE) {



More information about the Eventstudies-commits mailing list