Announcement

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

  • Matrix Calculation

    Good morning,

    I'm calculating with matrices and am building new matrices out of old ones, which shouldn't be an issue. However, the following is not accepted by Stata, returning an r(132) error (brackets/parenthesis error):

    matrix VWNOR = (
    EVNOR[1,1] / (EVNOR[1,1] + EVNOR[1,2]) \
    EVNOR[1,2] / (EVNOR[1,1] + EVNOR[1,2]))

    Where EVNOR is the following matrix:


    EVNOR[1,5]
    Eigenvalues: Eigenvalues: Eigenvalues: Eigenvalues: Eigenvalues:
    Comp1 Comp2 Comp3 Comp4 Comp5
    r1 3.7321743 .94771372 .26798242 .05102239 .00110712


    The above calcs should be working since [1,1-5] are all scalars, right? What's the issue? Thanks a lot for your inputs.

    Best,

    Peter

  • #2
    It is easier to get into Mata to do this. Stata's matrix language does not support many complicated expressions.

    Code:
    . matrix EVNOR = (3.7321743, .94771372, .26798242, .05102239, .00110712)
    
    . mata
    ------------------------------------------------- mata (type end to exit) --------------------------------
    : EVNOR = st_matrix("EVNOR")
    
    : VWNOR = (EVNOR[1,1] / (EVNOR[1,1] + EVNOR[1,2]) \ EVNOR[1,2] / (EVNOR[1,1] + EVNOR[1,2]))
    
    : VWNOR
                     1
        +---------------+
      1 |  .7974922229  |
      2 |  .2025077771  |
        +---------------+
    
    : vwnor = EVNOR[1..2]' :/ rowsum(EVNOR[1..2])
    
    : vwnor
                     1
        +---------------+
      1 |  .7974922229  |
      2 |  .2025077771  |
        +---------------+

    Comment


    • #3
      Great, thanks Nick. But how can I now save VWNOR as a matrix in regular Stata. I can display it in Mata but

      matrix list VWNOR

      in regular Stata does not display it....

      Thanks!

      Comment


      • #4
        Ok, I got it. Same command, other way around. Thanks

        Comment

        Working...
        X