Statalist


[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   wgould@stata.com (William Gould, StataCorp LP)
To   statalist@hsphsun2.harvard.edu
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 <PPetroulas@bankofgreece.gr> 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
wgould@stata.com
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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