Statalist The Stata Listserver


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

Re: st: Mata


From   "Raphael Fraser" <raphael.fraser@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Mata
Date   Tue, 25 Jul 2006 16:11:21 -0500

Thanks!

On 7/24/06, William Gould, Stata <wgould@stata.com> wrote:
Raphael Fraser <raphael.fraser@gmail.com> asks,

> How can I format numerical elements within a matrix in Mata? Just as
> one would format a variable say, format price %9.2f.

Mata matrices do not carry formats.  There are two solutions to dipslay a
matrix in formatted form.

First, you can write in Mata your own display loop:

        for (i=1; i<=rows(X); i++) {
                for (j=1; j<=cols(X); j++) {
                        printf("%9.2f  ", X[i,j])
                }
                printf("\n")
        }

Or, you can transfer the matrix to Stata and let Stata print it:

        st_matrix("tmpX", X)
        stata("matlist tmpX, ...")
        st_matrix("tmpX, J(0,0,.))

The last line deletes the the matrix tmpX.

-- 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/

*
*   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