help mata mm_matlist()
-------------------------------------------------------------------------------

Title

mm_matlist() -- Display a matrix and control the format

Syntax

void mm_matlist(X [, fmt, border, rstripe, cstripe, rtitle, save])

string colvector mm_smatlist(X [, fmt, border, rstripe, cstripe, rtitle])

where

X: real matrix X

fmt: string matrix fmt

border: real scalar border

rstripe: string vector rstripe

cstripe: string vector cstripe

rtitle: string scalar rtitle

save: object of any type; will be replaced

Description

mm_matlist() displays matrix X and lets you control the format. Wide matrices are broken into pieces to fit the window width.

fmt set the display format(s). Available formats are the usual numeric and date formats (see help format) as well as "%f" and "%g" meaning %11.0g, compressed, and "%e" meaning %11.8e, compressed (see help [M-5] printf()). The default format is "%9.0g".

border sets border style. border==0 omits the border lines. border==1 prints lines around all four sides (Mata default). border==2 uses a style similar to a one-way frequency table (lines between the row labels and table body and between the column labels and the table body; see help tabulate). border==3 uses a style similar to a coefficients table (like border==2 but with top and bottom lines; see help ereturn display). The default is border==1.

rstripe and cstripe may be used to provide row and column labels. The default is to print the row and column numbers. Specifying rstripe or cstripe as "" omits the labels. Specifying rstripe or cstripe as J(1,0,"") or J(0,1,"") is equivalent to not specifying the argument (i.e. row or column numbers will be printed).

rtitle specifies a title to be printed above the row labels.

If save is provided, no output is displayed, but is returned in save as string colvector. Breaking wide matrices into pieces is disabled in this case.

mm_smatlist() is like mm_matlist() but returns a string colvector containing the output. In fact, display(mm_smatlist(X)) is equivalent to mm_matlist(X), but uses more memory (and does not break wide matrices into pieces). mm_smatlist() is a shortcut to mm_matlist(..., save).

Remarks

Examples:

: X = uniform(2,2):*(100,1) : X 1 2 +-----------------------------+ 1 | 61.00572762 .0884897853 | 2 | 4.244257417 .2894746962 | +-----------------------------+

: mm_matlist(X) 1 2 +-------------------------+ 1 | 61.00573 .0884898 | 2 | 4.244257 .2894747 | +-------------------------+

: mm_matlist(X,("%9.0g","%8.4f"), 3, > ("weight", "mpg"), ("Coef.","p-value"), "price") -------------------------------- price | Coef. p-value ---------+---------------------- weight | 61.00573 0.0885 mpg | 4.244257 0.2895 --------------------------------

: mm_matlist(X*100,"%d") 1 2 +-------------------------+ 1 | 13sep1976 09jan1960 | 2 | 28feb1961 29jan1960 | +-------------------------+

: mm_matlist(J(2,2,1)) 1 2 +-------------------------+ 1 | 1 1 | 2 | 1 1 | +-------------------------+

: mm_matlist(J(2,2,1),"%g") 1 2 +---------+ 1 | 1 1 | 2 | 1 1 | +---------+

: S = mm_smatlist(X,"%g",2) : display(8*" ":+S) | 1 2 ----+------------------------- 1 | 61.0057276 .088489785 2 | 4.24425742 .289474696

mm_matlist() uses the sprintf() function to display the numbers, so fmt may also contain text, although this only seems of limited use. Example:

: mm_matlist(uniform(2,2),("x = %g","y = %g")) 1 2 +----------------------------------+ 1 | x = .29975603 y = .566944822 | 2 | x = .32776424 y = .068731192 | +----------------------------------+

Conformability

mm_matlist(X, fmt, border, rstripe, cstripe, rtitle, save): X: r x c fmt: 1 x 1 or r x 1 or 1 x c or r x c border: 1 x 1 rstripe: r x 1 or 1 x r or "" or J(0,1,"") or J(1,0,"") cstripe: 1 x c or c x 1 or "" or J(1,0,"") or J(0,1,"") rtitle: 1 x 1 save: will be replaced by ro x 1 result: void

mm_smatlist(X, fmt, border, rstripe, cstripe, rtitle): X: r x c fmt: 1 x 1 or r x 1 or 1 x c or r x c border: 1 x 1 rstripe: r x 1 or 1 x r or "" or J(0,1,"") or J(1,0,"") cstripe: 1 x c or c x 1 or "" or J(1,0,"") or J(0,1,"") rtitle: 1 x 1 result: ro x 1 ro, the number of output rows, is equal to r plus some rows containing borders and column labels.

Diagnostics

Using SMCL tags within fmt, rstripe, or cstripe (see help smcl) or specifying special characters in fmt such as, e.g., \n (see help [M-5] printf()) may mess up the output.

Source code

mm_matlist.mata

Author

Ben Jann, ETH Zurich, jann@soz.gess.ethz.ch

Also see