Announcement

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

  • How to do matrix exponential operation in Stata?

    Code:
    matrix A = (1,0,0,0,0\0.6,0,.4,0,0\0,.6,0,.4,0\0,0,.6,0,.4\0,0,0,0,1)
    matrix list A
    matrix B = A*A
    I know how to do A^2. Now I want to do A^20. How should I do this?

    Many thanks in advance!

  • #2
    1. You could do it in a loop:
    Code:
    matrix B = A
    forvalues j = 2/20 {
        matrix B = B * A
    }
    matrix list B
    2. Given that your matrix is diagonalizable with only real eigenvalues, you could use the eigenvalue decomposition, which is easier done in Mata:
    Code:
    mata:
        A = st_matrix("A")
        eigensystem(A, V, L)
        B = V * diag(L:^20) * luinv(V)
        st_matrix("B", Re(B))
    end
    matrix list B
    In case of a symmetric matrix, an even easier way would be to use the Mata function matpowersym().
    Last edited by Sebastian Kripfganz; 31 May 2019, 09:34.
    https://www.kripfganz.de/stata/

    Comment


    • #3
      Use Mata is the best advice, but for how this was done in 1999

      Code:
      search matpow, stb historical

      Comment

      Working...
      X