[R] Merging xts List created using panel data

Jairaj Gupta J.Gupta at 2012.hull.ac.uk
Wed Feb 5 01:07:37 CET 2014


Hi,

I have done the following:

library(foreign)
RNOM <- read.dta("Return Panel without missing.dta")
library(PerformanceAnalytics)
RNOM_list<-split(RNOM,RNOM$gvkey)
xtsList <- lapply(RNOM_list, function(x) {
  attrCol <- c("conm")
  numCol <- c("gvkey","prccm","trfm", "trt1m")
  y <- xts(x[,numCol], as.Date(x$datadate,format="%d/%m/%Y"))
  xtsAttributes(y) <- as.list(x[1,attrCol])
  y
})

logreturns <- lapply(xtsList, function(x) {
  Return.calculate(x$prccm, method = "log")
} )

Now I get, xts List of logreturns and xtsList of my data. 

Can anyone please tell me, how can I merge logreturns with my original dataframe or xtsList; and export it as a csv/excel file for further regression analysis (after merging the file needs to look like panel data)?

The description of variables is as follows:
datadate        long   %d                     Data Date - Security Monthly
gvkey           str6   %6s                    Global Company Key - Security Monthly Descriptor
conm            str58  %58s                   Company Name
prccm           double %20.0g                 Price - Close - Monthly
trfm            double %8.0g                  Monthly Total Return Factor
trt1m           double %8.0g                  Monthly Total Return
gvkeynum        long   %8.0g       gvkeynum   Global Company Key - Security Monthly Descriptor

The data can be downloaded from here: https://drive.google.com/file/d/0B8usDJAPeV85ZG1MSHNDeFQtM28/edit?usp=sharing


Thanks & Regards,


Jairaj Gupta
PhD Finance Candidate
Hull University Business School
Student No. 201201551
Mobile: 00-44-(0)7795904913
SSRN Author: http://ssrn.com/author=1936478
Linkedin Profile: http://www.linkedin.com/pub/jairaj-gupta/54/13a/b61
-------------- next part --------------
**************************************************
To view the terms under which this email is 
distributed, please go to 
http://www2.hull.ac.uk/legal/disclaimer.aspx
**************************************************


More information about the R-help mailing list