Statalist The Stata Listserver

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

Re: st: Mata

From (William Gould, Stata)
Subject   Re: st: Mata
Date   Mon, 24 Jul 2006 08:05:59 -0500

Raphael Fraser <> 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])

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
*   For searches and help try:

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