Announcement

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

  • Exporting a matrix from Mata to Stata preserving the entire set of decimal digits

    Dear all,

    I have a (probably simple) question regarding exporting a matrix from Mata to Stata.

    I am using Mata to perform a set of estimations, after which I store my resulting coefficients of interest in the matrix "results". Each entry of this matrix in Mata entails a large number of decimal digits: when displaying it in Mata, the output entails numbers with 9 decimal digits. Now, my aim is to export this results matrix to Stata. I tried the most common solution of using st_matrix(); however, the resulting Stata matrix gets rounded to the 7th decimal digit (this happens both when displaying in Stata, and when using its entries to perform other tasks). Is there a way of performing this export preserving the entire (i.e., not rounded) entries of the original Mata matrix?

    Thanks so much and best regards

    Pier Giuseppe

  • #2
    I wonder if this just a matter of the default display format for a matrix in Mata vs. in Stata? I can get the same decimal digits from the Stata matrix as the Mata matrix if I apply a display format when listing the Stata matrix. Here's an example:
    Code:
    . mata: M = runiform(3,1)
    . mata: M
                     1
        +---------------+
      1 |   .584465802  |
      2 |  .3697791432  |
      3 |  .8506309088  |
        +---------------+
    
    . mata: st_matrix("S", M)
    
    . // Back to Stata
    . mat list S
    
    S[3,1]
               c1
    r1   .5844658
    r2  .36977914
    r3  .85063091
    
    . // With format
    . mat list S, format(%15.10f)
    
    S[3,1]
                  c1
    r1  0.5844658020
    r2  0.3697791432
    r3  0.8506309088
    I'd note, however, that data that truly supports 10 decimal digits of precision is extremely unusual, so I wouldn't regard the difference between the two displays as meaningful.

    .

    Comment

    Working...
    X