[Eventstudies-commits] r295 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 30 06:27:08 CEST 2014
Author: chiraganand
Date: 2014-04-30 06:27:07 +0200 (Wed, 30 Apr 2014)
New Revision: 295
Modified:
pkg/R/eventstudy.R
Log:
Fixed lmAMM call for multiple firms, fixed lmAMM for single firm: handle univariate series gracefully.
Modified: pkg/R/eventstudy.R
===================================================================
--- pkg/R/eventstudy.R 2014-04-30 02:13:21 UTC (rev 294)
+++ pkg/R/eventstudy.R 2014-04-30 04:27:07 UTC (rev 295)
@@ -11,7 +11,7 @@
# type = "marketResidual", "excessReturn", "AMM", "None"
## arguments to the model
extra.var <- list(...)
-
+
if (type == "None" && !is.null(firm.returns)) {
outputModel <- firm.returns
}
@@ -23,6 +23,11 @@
### Run models
## AMM
if (type == "lmAMM") {
+ if (is.null(ncol(firm.returns))) {
+ stop("firm.returns should be a zoo series with at least one column. Use '[' with 'drop = FALSE'.")
+ }
+ firmNames <- colnames(firm.returns)
+
## AMM residual to time series
timeseriesAMM <- function(firm.returns, X, verbose = FALSE, nlags = 1) {
tmp <- resid(lmAMM(firm.returns = firm.returns,
@@ -53,7 +58,8 @@
verbose = FALSE,
nlags = 1)
})
- outputModel <- do.call("merge",tmp.resid)
+ outputModel <- zoo(tmp.resid,
+ order.by = as.Date(rownames(tmp.resid)))
}
} ## end AMM
@@ -71,7 +77,13 @@
index(outputModel) <- as.Date(index(outputModel))
### Convert to event frame
- es <- phys2eventtime(z=outputModel, events=eventList, width=0)
+ ## change the dimensions if there is only one firm
+ if (is.null(ncol(outputModel))) {
+ attr(outputModel, "dim") <- c(length(outputModel), 1)
+ attr(outputModel, "dimnames") <- list(NULL, firmNames)
+ colnames(outputModel) <- firmNames
+ }
+ es <- phys2eventtime(z = outputModel, events=eventList, width=0)
if (is.null(es$z.e) || length(es$z.e) == 0) {
es.w <- NULL
More information about the Eventstudies-commits
mailing list