title: Correlation matrix for panel data
body: <p>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:</p>
  
  <p>Therefore, my input file looks like</p>
  
  <pre><code>company ----year -----LEV-----DOI
  
  x-----------1 ---------6 -----10
  
  x-----------2 ---------6 -----10
  
  y-----------1 ---------6 -----10
  
  y-----------2 ---------6 -----10
  </code></pre>
  
  <p>Now I want to create a correlation matrix for the data set of the variables, it should look like:</p>
  
  <pre><code>---LEV------DOI----INDU----GROWTH
  
  LEV
  
  DOI
  
  INDU
  
  GROWTH
  </code></pre>
  
  <p>What I did so far:</p>
  
  <pre><code>Leverage_alle  &lt;- pdata.frame(Leverage, index=c("company", "year"))
  Lev_data       &lt;- Leverage_alle[Leverage_alle$id %in% c(1,2),c(1:4, 6:10)]
  </code></pre>
  
  <p>cor: function does not work if I use it in the following way:</p>
  
  <pre><code>cor(Leverage_alle,use = "pairwise.complete.obs")
  Error in cor(Leverage_alle, use = "pairwise.complete.obs"):'x' muss numerisch sein
  </code></pre>
  
  <p>I found the following coding, but do not know how to apply it to my case, because it </p>
  
  <pre><code>&gt; cor(acast(Lev_data, year ~ id, value.var = 'XY'), use = 'pairwise.complete.obs')
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>Lev_data %&gt;%
       spread(year, company) %&gt;%
       select(-year) %&gt;%
       cor(., use = "pairwise.complete.obs")
  
  Error in eval(lhs, parent, parent) : object 'paneldata' not found
  </code></pre>