Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: How do I suppress output in mata?


From   wgould@stata.com (William Gould, StataCorp LP)
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How do I suppress output in mata?
Date   Mon, 16 Nov 2009 11:19:41 -0600

Kramer <kramersdomain@yahoo.com> asked, 

> I've just written my first function in mata and I need some help.  
> [...]
>
>  The function works well, except for the fact that it returns the r x r
>  matrix to the screen.  [...]
> 
> I've tried typing "quietly" before I execute the function in mata, and
>  that returns the error.

Kramer has a function district() that he has written.  In Mata, if he 
invokes the funtion, he sees:

        : district((22\23\22))
        [symmetric]
               1   2   3
            +-------------+
          1 |  0          |
          2 |  0   0      |
          3 |  1   0   0  |
            +-------------+

If Kramer wants the result from the function saved in a Mata variable, 
he needs to store it there, and then Mata does not display the result:

        : x = district((22\23\22))

        : _


Kramer needs to understand, function -district()- returns something.
If Kramer specifies were the result is to go, the result is stored 
there.  If Kramer does not specify where the returned result is to 
be stored, the returned result id displayed.

Kramer talks about using this funtion from Stata.  Perhaps he wants the 
result stored in a Stata matrix.  If so, he would need to modify his 
code.  Right now, his code reads, 

        real matrix district(real colvector T)
        {
               ...                  // I omit showing the code
               return(WDY0)
        }

If Kramer wanted district() to save the result in Stata matrix george, 
he would modify the code to read, 

        void district(real colvector T)
        {
               ...                  // I omit showing the code
               st_matrix("george", WDY0)
        }

I changed Kramer's function to be void (to return nothing), dropped
the return() statement, and substituted -st_matrix("george", WDY0)-.

If Kramer wanted to modify his function to save the result in a Stata 
matrix of the name he specified, he would modify the code to read, 

        void district(real colvector T, string scalar name)
        {
               ...                  // I omit showing the code
               st_matrix(name, WDY0)
        }

-- Bill
wgould@stata.com
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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