Announcement

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

  • Error code when trying to put mata matrix back into Stata

    Hi
    Apologies if this is basic, I'm new to using mata and nothing from previous questions seems to work.
    I needed to switch into mata to use the eigensystem command and am now trying to return a single column matrix with 255 rows back into stata.

    I brought my data into mata with " w_tilde_mat = st_matrix("w_tilde") "
    I used " eigensystem(w_tilde_mat, v_vect_tilde=.,w_val_tilde=.) " to get a 255x255 matrix of 255, 255 row eigenvectors.
    I then used " col_ec = w_vect_tilde[.,2] " to extract the second eigenvector which is what I need.

    I then want to put col_ec back into stata, and am trying to use st_matrix again, and have tried various things but nothing works.
    For example st_matrix("col_ec", col_st_ec) returns an error code with col_st_ec not being found (3499) but this is what I want the matrix created back in stata to be called.

    Thanks in advance.

  • #2
    Code:
    mata
    M =J(5,6,7)
    st_matrix("StataM", M[1..., 2])
    end
    mat l StataM
    Res.:

    Code:
    . mat l StataM
    
    StataM[5,1]
        c1
    r1   7
    r2   7
    r3   7
    r4   7
    r5   7
    See

    Code:
    help matrix extraction

    I then want to put col_ec back into stata, and am trying to use st_matrix again, and have tried various things but nothing works. For example st_matrix("col_ec", col_st_ec) returns an error code with col_st_ec not being found (3499)
    In your case, the error message is meaningful as there is no matrix named "col_st_ec" defined. This should work:

    Code:
    st_matrix("col_st_ec", col_ec)
    where the Stata matrix will be named "col_st_ec".
    Last edited by Andrew Musau; 03 Aug 2022, 12:32.

    Comment

    Working...
    X