0
votes

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
1
Please spend some time reformatting your question, by using e.g. proper code blocks. At the moment this is a bit of a mess! Also consider (1) providing a minimal reproducible example including sample data, and (2) clearly stating your expected output.Maurits Evers

1 Answers

0
votes

All items in a correlation matrix must be numeric variables. My German is rusty, but the error message "muss numerische sein" means "must be numeric." Check the data types of each column you are trying to use in the cor() function. You've probably read some of the columns as factors, and therefore they need to be converted to numeric with the as.numeric() function.