I want to create a correlation matrix for my panel date set. My data set is structured in the following way, I have the following figures for companies for a time frame of 8 years: LEV, DOI, INDU, GROWTH, SIZE, ROE, AGE:
Therefore, my input file looks like
company ----year -----LEV-----DOI
x-----------1 ---------6 -----10
x-----------2 ---------6 -----10
y-----------1 ---------6 -----10
y-----------2 ---------6 -----10
Now I want to create a correlation matrix for the data set of the variables, it should look like:
---LEV------DOI----INDU----GROWTH
LEV
DOI
INDU
GROWTH
What I did so far:
Leverage_alle <- pdata.frame(Leverage, index=c("company", "year"))
Lev_data <- Leverage_alle[Leverage_alle$id %in% c(1,2),c(1:4, 6:10)]
cor: function does not work if I use it in the following way:
cor(Leverage_alle,use = "pairwise.complete.obs")
Error in cor(Leverage_alle, use = "pairwise.complete.obs"):'x' muss numerisch sein
I found the following coding, but do not know how to apply it to my case, because it
> cor(acast(Lev_data, year ~ id, value.var = 'XY'), use = 'pairwise.complete.obs')
I also tried:
Lev_data %>%
spread(year, company) %>%
select(-year) %>%
cor(., use = "pairwise.complete.obs")
Error in eval(lhs, parent, parent) : object 'paneldata' not found