Hosting the data. It consists of all firms with RM inventory greater than $10 million in four 6 digit NAICS codes
db1<- read.csv("https://docs.google.com/spreadsheets/d/1C7J2ZGo56I7fRfDuIZuH3dTnl9TUYtrKLgSrkBJF324/pub?output=csv", header = TRUE)
names(db1)
## [1] "gvkey" "datadate" "fyearq" "fqtr" "yq" "conm"
## [7] "cogsq" "invfgq" "invrmq" "invwipq" "niq" "revtq"
## [13] "opin" "naics"
dim(db1)
## [1] 912 14
We create variables for inventory coverage
db1$rmt <- db1$cogsq/db1$invrmq
db1$wipt <- db1$cogsq/db1$invwipq
db1$fgt <- db1$revtq/db1$invfgq
Remove observations that have NA or 0 as inventory turns. We will lose some observations
db2 <- db1[which(db1$rmt>0 & db1$wipt>0 & db1$fgt>0 & db1$fgt<10),]
dim(db2)
## [1] 731 17
We define a function to calculate the correlation matrix with stars for significance. The function is taken form here: http://myowelt.blogspot.com/2008/04/beautiful-correlation-tables-in-r.html
corstarsl <- function(x){
require(Hmisc)
x <- as.matrix(x)
R <- rcorr(x)$r
p <- rcorr(x)$P
## define notions for significance levels; spacing is important.
mystars <- ifelse(p < .001, "***", ifelse(p < .01, "** ", ifelse(p < .05, "* ", " ")))
## trunctuate the matrix that holds the correlations to two decimal
R <- format(round(cbind(rep(-1.11, ncol(x)), R), 2))[,-1]
## build a new matrix that includes the correlations with their apropriate stars
Rnew <- matrix(paste(R, mystars, sep=""), ncol=ncol(x))
diag(Rnew) <- paste(diag(R), " ", sep="")
rownames(Rnew) <- colnames(x)
colnames(Rnew) <- paste(colnames(x), "", sep="")
## remove upper triangle
Rnew <- as.matrix(Rnew)
Rnew[upper.tri(Rnew, diag = TRUE)] <- ""
Rnew <- as.data.frame(Rnew)
## remove last column and return the matrix (which is now a data frame)
Rnew <- cbind(Rnew[1:length(Rnew)-1])
return(Rnew)
}
corstarsl(db2[,13:15])
## Loading required package: Hmisc
## Warning: package 'Hmisc' was built under R version 3.3.3
## Loading required package: lattice
## Loading required package: survival
## Warning: package 'survival' was built under R version 3.3.3
## Loading required package: Formula
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.3.3
##
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
##
## format.pval, round.POSIXt, trunc.POSIXt, units
## opin naics
## opin
## naics -0.03
## rmt 0.37*** -0.12**
names(db2)
## [1] "gvkey" "datadate" "fyearq" "fqtr" "yq" "conm"
## [7] "cogsq" "invfgq" "invrmq" "invwipq" "niq" "revtq"
## [13] "opin" "naics" "rmt" "wipt" "fgt"