Announcement

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

  • Save the matrix output as stata data

    Dear Statalisters,

    I ran
    matrix symeigen X L = newA

    in stata13, and see the results in matrix form in output window.

    I want to save the results of vector X and L as stata data.


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    as a reference: I posted earlier this message,

    http://www.statalist.org/forums/foru...-stata-dataset

    then it occurs to me, my matrix symeigen is not executed using mata, so I ask this question here. I hope it is not against the posting etiquette.

    By the way, another part of my program where I generate a symmetric matrix in mata, I try to save the symmetric matrix as a stata dataset using getmata, I got error code" invalid lval
    r(3000);"

    here is the code:


    ~~~~~~~~~~~~~~~
    mata


    M = st_matrix("A")

    void function makesym(matrix M) {
    if (rows(M)!=cols(M)) {
    exit(error(1))
    }
    for(i=1;i<=rows(M);i++) {
    for(j=1;j<i;j++) {
    mx=max(M[i,j] \ M[j,i])
    M[i,j]=mx
    M[j,i]=mx
    }
    }
    }

    makesym(M)

    getmata (myvar*) = M


    end
    ~~~~~~~~~~~~~~~

    thanks for your consideration ,


    Rochelle

  • #2
    Hi Rochelle The getmata statement has to come after end, since it is a Stata command. Otherwise try to use svmat with your Stata code. See help mkmat. Best Christophe

    Comment


    • #3
      Hi Christophe,

      thanks for your suggestion!

      I changed my code according, please see error code below:

      mata


      M = st_matrix("A")

      void function makesym(matrix M) {
      if (rows(M)!=cols(M)) {
      exit(error(1))
      }
      for(i=1;i<=rows(M);i++) {
      for(j=1;j<i;j++) {
      mx=max(M[i,j] \ M[j,i])
      M[i,j]=mx
      M[j,i]=mx
      }
      }
      }

      makesym(M)


      matrix list A
      * A[473,473]

      matrix list M

      st_matrix("newA",M)


      end

      getmata (myvar*) = M

      " rows of matrix != _N
      The matrix contains 473 rows and the data have 223729 observations. Specify putmata's option id() to
      control alignment or specify option force to align with the first observation and to extend the data
      if necessary.

      my matrix A is 473*473, and 223,729 observations.

      Best,
      Rochelle

      Comment


      • #4
        Try to use the force option, it should solve the problem.

        Comment


        • #5
          Thanks again

          Comment

          Working...
          X