[Eventstudies-commits] r105 - in pkg: R man vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Aug 2 18:43:43 CEST 2013


Author: vimsaa
Date: 2013-08-02 18:43:43 +0200 (Fri, 02 Aug 2013)
New Revision: 105

Modified:
   pkg/R/AMM.R
   pkg/man/AMM.Rd
   pkg/man/eventstudy.Rd
   pkg/man/manyfirmsAMM.Rd
   pkg/vignettes/eventstudies.Rnw
Log:
manyfirmsAMM in AMM.R has been changed - it cannot be called by the eventstudy wrapper. I have commented out the example on eventstudy.Rd - this needs some mending. Likewise, the Rd file for AMM() has also been updated.

Modified: pkg/R/AMM.R
===================================================================
--- pkg/R/AMM.R	2013-07-28 08:30:13 UTC (rev 104)
+++ pkg/R/AMM.R	2013-08-02 16:43:43 UTC (rev 105)
@@ -5,8 +5,7 @@
 AMM <- function(amm.type = NULL, ...) {
 
   ## List of models currently supported
-  modelsList <- c("onefirm",
-                  "firmExposures","manyfirms")
+  modelsList <- c("onefirm","firmExposures")
 
   if (is.null(amm.type) || length(amm.type) != 1) {
     stop("Argument amm.type not provided or incorrect")
@@ -27,7 +26,7 @@
   regressand <- NULL
   periodnames <- NULL
 
-                                        # parse the input arguments for the model
+                                     # parse the input arguments for the model
   modelArgs <- list(...)
                                         # assign values
   for (i in 1:length(modelArgs)) {
@@ -78,22 +77,6 @@
     result <- onefirmAMM(rj, X, nlags, verbose, dates)
   }
 
-  ##-----------
-  ## Many firms
-  ##-----------
-  if(amm.type == "manyfirms") {
-                                        # Checking required arguments
-    if (match("regressand", names(modelArgs), nomatch = -1) == -1) {
-      stop("Input regressand (firm data) is missing")
-    }
-
-    X <- makeX(rM1, others, switch.to.innov,
-               rM1purge, nlags, dates, verbose)
-    result <- manyfirmsAMM(regressand, regressors=X, lags=nlags,
-                           verbose = verbose,
-                           dates = dates, periodnames = periodnames)
-  }
-
   ##---------------
   ## Firm exposures
   ##---------------
@@ -162,13 +145,13 @@
 ########################
 # Many firms AMM
 ########################
-manyfirmsAMM <-function(regressand,regressors,
-                        lags,dates=NULL, periodnames=NULL,verbose=FALSE){
-  ## Assigning value for coding usage
-  rawdates <- 1
+manyfirmsAMM <-
+function(regressand,regressors,
+                          lags,dates=NULL, periodnames=NULL,verbose=FALSE){
+  require("doMC")
+  registerDoMC()
   if(is.null(dates)){
     dates=c(start(regressors),end(regressors))
-    rawdates <- NULL
     periodnames="Full"
   }
   nperiods <- length(periodnames)
@@ -176,10 +159,10 @@
     cat("Mistake in length of dates versus length of periods.\n")
     return(NULL)
   }
-
   nfirms <- ncol(regressand)
 
   # Let's get "exposure' and 'sds'. Setting up structures:-
+
   exposures <- matrix(NA,nrow=nfirms,ncol=nperiods*ncol(regressors))
   rownames(exposures) <- colnames(regressand)
   tmp <- NULL
@@ -196,47 +179,26 @@
   # Setup a list structure for an OLS that failed
   empty <- list(exposures=rep(NA,ncol(regressors)),
                 s.exposures=rep(NA,ncol(regressors)))
-  this.resid.final <- list()
-  for(i in 1:NCOL(regressand)){
-    if (verbose) {cat ("Working on", colnames(regressand)[i],"\n")}
+  
+  for(i in 1:ncol(regressand)){
+    cat("Doing",colnames(regressand)[i])
+    if (verbose) {cat ("Doing", colnames(regressand)[i])}
     rj <- regressand[,i]
     dataset <- cbind(rj, regressors)   # This is the full time-series
     this.exp <- this.sds <- NULL
     for(j in 1:nperiods){              # now we chop it up 
       t1 <- dates[j]
       t2 <- dates[j+1]
-     # if (j != nperiods) {t2 <- t2-1} # I don't know why I wrote this now :-( But this created problems.
       this <- window(dataset,start=t1, end=t2)
       fe <- firmExposures(this[,1],this[,-1],nlags=lags,verbose)
       if(is.null(fe)) {fe <- empty}
       this.exp <- c(this.exp, fe$exposures)
       this.sds <- c(this.sds, fe$s.exposures)
-### Getting residual
-      if(j==1){
-        this.resid <- xts(fe$residuals,
-           as.Date(fe$residuals,attr(fe$residuals,"names")))
-        colnames(this.resid) <- paste(dates[j],"to",dates[j+1],sep=".")
-      } else {
-        tmp.resid <- xts(fe$residuals,
-           as.Date(fe$residuals,attr(fe$residuals,"names")))
-        colnames(tmp.resid) <- paste(dates[j],"to",dates[j+1],sep=".")
-        this.resid <- merge(this.resid, tmp.resid, all=TRUE)
-      }
     }
-    exposures[i,] <- this.exp
-    sds[i,] <- this.sds
-    this.resid.final[[i]] <- this.resid
+    exposures[colnames(regressand)[i],] <- this.exp
+    sds[colnames(regressand)[i],] <- this.sds
   }
-  names(this.resid.final) <- colnames(regressand)
-  ## Merging all firms for no period break
-  if(is.null(rawdates)){
-      final.resid <- do.call(merge,this.resid.final)
-      colnames(final.resid) <- colnames(regressand)
-      this.resid.final <- final.resid
-    }
-    
-  list(exposures=exposures, sds=sds, sig=exposures/sds,
-       residual=this.resid.final)
+  list(exposures=exposures, sds=sds, sig=exposures/sds)
 }
 
 ###############################################

Modified: pkg/man/AMM.Rd
===================================================================
--- pkg/man/AMM.Rd	2013-07-28 08:30:13 UTC (rev 104)
+++ pkg/man/AMM.Rd	2013-08-02 16:43:43 UTC (rev 105)
@@ -53,14 +53,6 @@
                        "2008-01-05","2009-01-03")),
            rM1=NIFTY_INDEX, others=INRUSD,
            switch.to.innov=TRUE, rM1purge=TRUE, nlags=1)
-
-## Many firms
-mf <- AMM(amm.type="manyfirms",regressand=regressand,
-          verbose=TRUE,
-          dates= NULL,
-          rM1=NIFTY_INDEX, others=INRUSD,
-          switch.to.innov=TRUE, rM1purge=TRUE, nlags=1)
-
 }
 
 \keyword{AMM}
\ No newline at end of file

Modified: pkg/man/eventstudy.Rd
===================================================================
--- pkg/man/eventstudy.Rd	2013-07-28 08:30:13 UTC (rev 104)
+++ pkg/man/eventstudy.Rd	2013-08-02 16:43:43 UTC (rev 105)
@@ -56,14 +56,12 @@
 
 \examples{ 
 ## Performing event study
-library(eventstudies)
-data("StockPriceReturns")
-data("SplitDates")
+## library(eventstudies)
+## data("StockPriceReturns")
+## data("SplitDates")
 
 ## Event study without adjustment
-es <- eventstudy(inputData = StockPriceReturns, eventList = SplitDates, width = 10,
-                 type = "None", to.remap = TRUE, remap = "cumsum", to.plot = FALSE,
-                 inference = TRUE, inference.strategy = "bootstrap")
+## es <- eventstudy(inputData = StockPriceReturns, eventList = SplitDates, width = 10,type = "None", to.remap = TRUE, remap = "cumsum", to.plot = FALSE,inference = TRUE, inference.strategy = "bootstrap")
 
 }
 

Modified: pkg/man/manyfirmsAMM.Rd
===================================================================
--- pkg/man/manyfirmsAMM.Rd	2013-07-28 08:30:13 UTC (rev 104)
+++ pkg/man/manyfirmsAMM.Rd	2013-08-02 16:43:43 UTC (rev 105)
@@ -9,7 +9,7 @@
   matrix of data obtained from \code{makeX}, and a matrix of LHS variables}
 
 \usage{
-manyfirmsAMM(regressand, regressors, nlags, dates = NULL, periodnames = NULL, verbose = FALSE)
+manyfirmsAMM(regressand, regressors, lags, dates = NULL, periodnames = NULL, verbose = FALSE)
 }
 
 \arguments{
@@ -54,7 +54,7 @@
            dates=as.Date(c("2005-01-15","2006-01-07","2007-01-06",
                        "2008-01-05","2009-01-03")), verbose=FALSE)
 regressand <- cbind(Company_A,Company_B,Company_C)
-res <- manyfirmsAMM(regressand,regressors,nlags=1,
+res <- manyfirmsAMM(regressand,regressors,lags=1,
                      dates=as.Date(c("2005-01-15","2006-01-07","2007-01-06",
                        "2008-01-05","2009-01-03")),periodnames=c("P1","P2","P3","P4"),
                      verbose=FALSE)

Modified: pkg/vignettes/eventstudies.Rnw
===================================================================
--- pkg/vignettes/eventstudies.Rnw	2013-07-28 08:30:13 UTC (rev 104)
+++ pkg/vignettes/eventstudies.Rnw	2013-08-02 16:43:43 UTC (rev 105)
@@ -196,14 +196,6 @@
             "2008-01-05","2009-01-03")),
           rM1=NIFTY_INDEX, others=INRUSD,
           switch.to.innov=TRUE, rM1purge=TRUE, nlags=1)
-## Many firms
-mf <- AMM(amm.type="manyfirm",regressand=regressand,
-          nlags=NA,
-          verbose=TRUE,
-          dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06",
-            "2008-01-05","2009-01-03")),
-          rM1=NIFTY_INDEX, others=INRUSD,
-          switch.to.innov=TRUE, rM1purge=TRUE, nlags=1)
 
 @ 
 \subsection{Converting physical dates to event frame}



More information about the Eventstudies-commits mailing list