Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Variance Covariance Matrix for Panel Data for each Year

    Dear Stata community:
    I have the following simple question. Suppose I have panel data and 10 variables. My data is from year 1989 to 2016.
    How can I compute the variance-covariance matrix for each year and store it as a variable?
    I know if I use:
    correlate d1-d10, covariance
    I get variance-covariance for all the years from 1989-2016.
    CompanyID YEAR d1 d2 d3 d4 d5 d6 d7 d8 d9 d10
    1 1989 0.1 3 3 3 3 20 21 22 23 24
    1 1990 5 2 2 2 5 20 19 18 17 16
    1 1991 6 2 2 2 6 20 25 30 35 40
    2 1989 20 2 2 2 7 20 19 18 17 16
    2 1990 7 2 2 2 8 20 19 18 17 16
    2 1991 10 2 2 2 9 20 19 18 17 16

  • #2
    I do:
    search corrmat
    Is this package going to work?

    Comment


    • #3
      I have no idea what your second post means. You certainly can set up a loop over years, calculate the coverance matrix for each year and then do whatever you want with that matrix.

      That is something like:
      forvalues t=2001/2006 {
      corr d* if year==`t'
      **need to write matrix somewhere here**
      }

      Alternatively, it looks like you could loop and use corrmat instead of corr.

      I don't know how you want to write the covariance matrix. You could save the matrices as matrices (simply given the a base name and put the `t' at the end of it: matrix corr`t'=r(C)) or use corrmat's facility to save a matrix. But if you want to store it as a variable you'll have to figure how you're going to do that. If you want to write these in different variables (i.e. put each element in a different variable but stack the years one after the other, you can generate the needed variables before the loop as missing (i.e., g corrd1d2=.) and then replace the value for each year.

      Comment

      Working...
      X