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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Feb 18 07:18:26 CET 2014


Author: vikram
Date: 2014-02-18 07:18:26 +0100 (Tue, 18 Feb 2014)
New Revision: 175

Modified:
   pkg/R/lmAmm.R
   pkg/man/manyfirmssubperiod.lmAMM.Rd
   pkg/vignettes/eventstudies.Rnw
Log:
Changed argument for manyfirmssubperiod.lmAMM function to have uniformity across all functions

Modified: pkg/R/lmAmm.R
===================================================================
--- pkg/R/lmAmm.R	2014-02-18 03:23:27 UTC (rev 174)
+++ pkg/R/lmAmm.R	2014-02-18 06:18:26 UTC (rev 175)
@@ -65,12 +65,12 @@
 # Many firms AMM
 ########################
 manyfirmssubperiod.lmAMM <-
-function(regressand,regressors,
+function(firm.returns,X,
                           lags,dates=NULL, periodnames=NULL,verbose=FALSE){
   require("doMC")
   registerDoMC()
   if(is.null(dates)){
-    dates=c(start(regressors),end(regressors))
+    dates=c(start(X),end(X))
     periodnames="Full"
   }
   nperiods <- length(periodnames)
@@ -78,16 +78,17 @@
     cat("Mistake in length of dates versus length of periods.\n")
     return(NULL)
   }
-  nfirms <- ncol(regressand)
+  nfirms <- ncol(firm.returns)
 
   # Let's get "exposure' and 'sds'. Setting up structures:-
 
-  exposures <- matrix(NA,nrow=nfirms,ncol=nperiods*ncol(regressors))
-  rownames(exposures) <- colnames(regressand)
+  exposures <- matrix(NA,nrow=nfirms,ncol=nperiods*ncol(X))
+  exposures <- as.data.frame(exposures)
+  rownames(exposures) <- colnames(firm.returns)
   tmp <- NULL 
   for(i in 1:length(periodnames)){
-    for(j in 1:ncol(regressors)){
-      tmp <-  c(tmp, paste(colnames(regressors)[j],
+    for(j in 1:NCOL(X)){
+      tmp <-  c(tmp, paste(colnames(X)[j],
                            periodnames[i],sep="."))
     }
   }
@@ -96,14 +97,14 @@
   colnames(sds) <- paste("sd",colnames(exposures),sep=".")
 
   # Setup a list structure for an OLS that failed
-  empty <- list(exposures=rep(NA,ncol(regressors)),
-                s.exposures=rep(NA,ncol(regressors)))
+  empty <- list(exposures=rep(NA,ncol(X)),
+                s.exposures=rep(NA,ncol(X)))
   
-  for(i in 1:ncol(regressand)){
-    cat("Doing",colnames(regressand)[i],"\n")
-    if (verbose) {cat ("Doing", colnames(regressand)[i], "\n")}
-    firm.returns <- regressand[,i]
-    dataset <- cbind(firm.returns, regressors)   # This is the full time-series
+  for(i in 1:NCOL(firm.returns)){
+    cat("AMM estimation for",colnames(firm.returns)[i],"\n")
+    if (verbose) {cat ("AMM estimation for", colnames(firm.returns)[i], "\n")}
+    stock.return <- firm.returns[,i]
+    dataset <- cbind(stock.return, X)   # This is the full time-series
     this.exp <- this.sds <- NULL
     for(j in 1:nperiods){              # now we chop it up 
       t1 <- dates[j]
@@ -114,8 +115,8 @@
       this.exp <- c(this.exp, fe$exposures)
       this.sds <- c(this.sds, fe$s.exposures)
     }
-    exposures[colnames(regressand)[i],] <- this.exp
-    sds[colnames(regressand)[i],] <- this.sds
+    exposures[colnames(firm.returns)[i],] <- this.exp
+    sds[colnames(firm.returns)[i],] <- this.sds
   }
   list(exposures=exposures, sds=sds, sig=exposures/sds)
 }

Modified: pkg/man/manyfirmssubperiod.lmAMM.Rd
===================================================================
--- pkg/man/manyfirmssubperiod.lmAMM.Rd	2014-02-18 03:23:27 UTC (rev 174)
+++ pkg/man/manyfirmssubperiod.lmAMM.Rd	2014-02-18 06:18:26 UTC (rev 175)
@@ -9,14 +9,14 @@
   matrix of data obtained from \code{makeX}, and a matrix of LHS variables}
 
 \usage{
-manyfirmssubperiod.lmAMM(regressand, regressors, lags, dates = NULL, periodnames = NULL, verbose = FALSE)
+manyfirmssubperiod.lmAMM(firm.returns, X, lags, dates = NULL, periodnames = NULL, verbose = FALSE)
 }
 
 \arguments{
-  \item{regressand}{A zoo matrix of all firms for which AMM is to
+  \item{firm.returns}{A zoo matrix of all firms for which AMM is to
   be computed}
 
-  \item{regressors}{A zoo matrix containing at least two
+  \item{X}{A zoo matrix containing at least two
   regressors generally obtained after applying the makeX function }
 
   \item{lags}{ Specifies the number of lags to be used in the
@@ -37,22 +37,22 @@
 \author{Ajay Shah, Vimal Balasubramaniam}
 
 \seealso{
-\code{\link{onefirmAMM}}
+\code{\link{lmAMM}}
 }
 
 \examples{
 # Running manyfirmssubperiod.lmAMM() involves as many steps as working with onefirmAMM. 
 data("lmAMMData")
-regressand <- lmAMMData[,c("Infosys","TCS")]
+firm.returns <- lmAMMData[,c("Infosys","TCS")]
 market.returns <- lmAMMData[,"index.nifty"]
 currency.returns <- lmAMMData[,"currency.inrusd"]
-## Creating regressors for AMM estimation using makeX function
-regressors <- makeX(market.returns, others=currency.returns, nlags=1,
+## Creating X for AMM estimation using makeX function
+X <- makeX(market.returns, others=currency.returns, nlags=1,
               switch.to.innov=FALSE, market.returns.purge=FALSE, verbose=FALSE,
-	      dates=as.Date(c("2012-02-01","2013-01-01","2014-01-31")))
+	      dates=as.Date(c("2012-02-01","2013-01-01","2014-01-20")))
 ## Estimating exposure
-res <- manyfirmssubperiod.lmAMM(regressand,regressors,lags=1,
-                     dates=as.Date(c("2012-02-01","2013-01-01","2014-01-31")),
+res <- manyfirmssubperiod.lmAMM(firm.returns,X,lags=1,
+                     dates=as.Date(c("2012-02-01","2013-01-01","2014-01-20")),
 		     periodnames=c("P1","P2"),
                      verbose=FALSE)
 print(res)

Modified: pkg/vignettes/eventstudies.Rnw
===================================================================
--- pkg/vignettes/eventstudies.Rnw	2014-02-18 03:23:27 UTC (rev 174)
+++ pkg/vignettes/eventstudies.Rnw	2014-02-18 06:18:26 UTC (rev 175)
@@ -91,15 +91,25 @@
   
 \item \texttt{marketResidual}: estimation of market model to obtain idiosyncratic firm returns, controlling for the market returns. 
   
-\item \texttt{AMM}: estimation of the augmented market model which provides user the capability to run market models with orthogonalisation and obtain idiosyncratic returns. 
+\item \texttt{lmAMM}: estimation of the augmented market model which provides user the capability to run market models with orthogonalisation and obtain idiosyncratic returns. 
 
 \end{itemize}
- 
-The function \texttt{AMM} is a generic function that allows users to
-run an augmented market model and undertake the analysis of the market
-model in a regression setting and obtain idiosyncratic returns. Often times, there is a need for an auxilliary regression that purges the effect of the explanatory variables on one another. This function allows for the estimation of such a residual for a single firm using the function \texttt{onefirmAMM}. Advanced users may also want to look at \texttt{manyfirmsAMM}. 
+The function \texttt{lmAMM} is a generic function that allows users to
+run an augmented market model (AMM) by using regressors provided by
+\texttt{makeX} function and undertake the analysis of the market model
+in a regression setting and obtain idiosyncratic
+returns. The auxiliary regression that purges the effect of the
+explanatory variables on one another is performed using \texttt{makeX}
+function. \texttt{subpperiod.lmAMM} function allows for a single firm
+AMM analysis for different periods in the sample. While
+\texttt{manyfirmssubperiod.lmAMM}\footnote{User can use this function
+  to perform AMM for more than one firm by providing argument \textit{dates=NULL}} replicates the
+\texttt{subperiod.lmAMM} analysis for more than one firms. 
 
-The output from all these models are also time series objects of class ``zoo'' or ``xts''. This becomes the input for the remaining steps in the event study analysis, of which the first step is to convert a timeseries object into the event-time frame.
+The output of \texttt{lmAMM} function is an list object of class
+\texttt{amm}. It includes the linear model output along with AMM
+exposure, standard deviation, significance and residuals. These AMM
+residuals are further used in event study analysis.
 
 \subsection{Converting data from physical time into event time}
 
@@ -190,17 +200,16 @@
 available. In this case, we would like to purge any currency returns
 from the outcome return of interest, and the \textit{a-priori}
 expectation is that the variance of the residual is reduced in this
-process. In this case, the \texttt{AMM} model requires a time-series
-of the exchange rate along with firm returns and market returns. This
-is done by loading the \textit{inr} data, which is the INR-USD
-exchange rate for the same period. The complete data set consisting of
-stock returns, market returns, and exchange rate is first created.
+process. In this case, the model requires a time-series of the
+exchange rate along with firm returns and market returns. The complete
+data set consisting of firm returns, market returns and exchange rate
+for the same period\footnote{A balanced data without NAs is preferred}
+is first created.  
 
-Inputs into the \texttt{AMM} model also include \texttt{firm.returns}
-and \texttt{market.returns}. Currency returns can be specified using
-\texttt{others}. In a general case, this proves to be a specification
-with the flexibility to run auxiliary regressions to specify the
-regression appropriately.
+The first step is to create regressors using market returns and
+exchange rate using \texttt{makeX} function. The output of
+\texttt{makeX} function is further used in \texttt{lmAMM} along with
+firm returns to compute augmented market model residuals.
 
 % AMM model
 <<>>= # Create RHS before running lmAMM() 
@@ -356,8 +365,6 @@
   2013}).  R itself as well as these packages can be obtained from
 \href{http://CRAN.R-project.org/}{CRAN}.
 
-
-
 % \newpage
 \bibliographystyle{jss} \bibliography{es}
 



More information about the Eventstudies-commits mailing list