[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: How does one export Mata matrices to Stata matrix language matrices?

From (William Gould, StataCorp LP)
Subject   Re: st: How does one export Mata matrices to Stata matrix language matrices?
Date   Fri, 26 Oct 2007 11:35:34 -0500

Petroulas Pavlos <> asks, 

>  If I am in Stata and for memory preserving reasons I enter Mata (instead of
>  using Stata's matrix language) do certain matrix operation, I would then
>  like to exit Mata but keep the matrices in Stata's memory: How do I do
>  this? (I.e with mat dir in Statas matrix language I would like for some
>  matrices that I've created in Mata to show up)

He is asking about this in the context of using Mata interactively.

Matrices during a Stata session

     Mata clears itself when you say to do so, which you can do in 
     three ways:

         1.  Typing -mata clear- to the Mata (:) prompt.

         2.  Typing -clear mata- to the Stata (.) prompt.

         3.  Typing -clear all- to the Stata (.) prompt.

      Mata does not clear itself automatically.  That means Mata remembers 
      matrices between Mata sessions within the same Stata session.

             . mata
             : A = (1,2,3)
             : end

             . use mydata, clear 

             . mata
             : A
             <matrix A will be displayed>
             : end

Matrices across Stata sessions

     You can interactively save matrices in a file.  Here's an example:

             . mata

             : A = (1,2,3)
             : B = (4,5)
             : mata matsave mymats A B

             : mata clear 
             : A
             <A will not be found>

             : mata matuse mymats
             : A
             <A will be displayed>

             : B
             <B will be displayed>

             : end

    -mata matsave mymats A B- will create file mymats.mmat.  .mmat is the 
    default file extension.  

    You can type -mata matdescribe mymats- to find out what is in a file
    without loading it.

     See -help mata matsave-.

Advanced stuff

    -mata matsave-, -mata matdescribe-, and -mata matuse- are for 
    interactive use.  If you want to save matrices in a file within a 
    program, see -help mata fopen()-.

    As a matter of fact, -mata matsave-, -mata matdescribe-, and -mata matuse-
    are written in terms of -fopen()-.  If you interested, see

            . viewsoure mata_matsave.ado

            . viewsoure mata_matuse.ado

            . viewsoure mata_matdescribe.ado

            . viewsource mmat_.mata 

    Easiest is simply to type -help mata matsave-, scroll down, and click 
    on the filenames under heading "Source code".

-- Bill
*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index