Announcement

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

  • Export mata from stata to txt

    Hi everyone!
    Do you know how to export a matrix that I did in stata with mata into a txt file? Thank you !
    Best,
    Clara

  • #2
    Dear Clara
    Could you elaborate on your problem? Eg create some example code showing what you have?
    Kind regards

    nhb

    Comment


    • #3
      I have create a matrix (called S, explained in the last post here https://www.statalist.org/forums/for...se-of-matrix); I would like to export it in a text document in order to inverse this matrix in another software (it does not work with stata as I explained in the last post).
      Clara

      Comment


      • #4
        Dear Clara
        Your does not work.
        Kind regards

        nhb

        Comment


        • #5
          Oh Sorry! https://www.statalist.org/forums/for...erse-of-matrix

          Comment


          • #6
            To save any other responders needing to get the context from other posts, I'm answering this question as: "I have a Mata matrix. How do I save it to a text file?"

            While there's doubtless a direct Mata way to do this, an easier solution for me is to get the Mata matrix into a Stata data set, and then export the Stata data set. Note that -export delimited- gives you control over formatting and the like of the text file you create. I've chosen to delimit the file with spaces (rather than tabs, commas, etc.), and to use the variables' default display format. This could be done as a Mata call to a Stata command, but I'm presuming that this export will likely be wanted after the Mata code is done, so I figured doing the export directly from Stata would be ok:
            Code:
            clear
            // Example matrix
            mata: S = runiform(200,200)
            //
            // preserve Stata data here if desired
            clear
            getmata SS* = S
            export delimited SS* using "c:/temp/mymatrix.txt", ///
               delimiter(" ") novarnames nolabel datafmt replace
            // restore Stata data here if necessary


            Comment


            • #7
              Thank you very much !

              Comment

              Working...
              X