Statalist The Stata Listserver


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

Re: st: Mata


From   "Raphael Fraser" <[email protected]>
To   [email protected]
Subject   Re: st: Mata
Date   Tue, 25 Jul 2006 16:11:21 -0500

Thanks!

On 7/24/06, William Gould, Stata <[email protected]> wrote:
Raphael Fraser <[email protected]> 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
[email protected]
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index