help for mmat2tex

Title

mmat2tex - export Mata Matrix to LaTeX Table.

Syntax

mmat2tex mata-matrixname using filename [, replace append fmt(fmt)
preheader(string) postheader(string) rownames)string) colnames(string)
substitute(string) insertendrow(string) coldelimiter(string) rowdelimiter(string)
coefficient(options) show	]

Description

mmat2tex writes mata matrix mata-matrixname as a LaTeX table into filename.
Only the body of the table (i.e. rows and columns) is created, but the LaTeX commands can be included using the options preheader and bottom.
The mata matrix can be string, real or complex. mmat2tex includes a program which delays read/write commands in case the file cannot opened/saved.
After 5 occurences it aborts with an error.

Options

replace specifies that the file will be replaced, while append puts the table at the end of an existing file.
Both cannot used together. If none is specified replace is assumed.

fmt(fmt) format for table. Default ist "%12.2f".
It is possible to set column specific formats.
For example fmt(%12.2f %10.4f) sets the format 12.2f for the first column and for the second and all following %10.4f format.

preheader(string)/postheader(string) adds text to the beginning (i.e. before the first and into the first cell) and the end (i.e. after the header) of the table head.

colnames(string)/rownames(string) specifies column and row names.

bottom(string)	adds text at the bottom of the table.

substitute(string) substitutes strings at the end. eg: substitute(col1 "Column Name") replaces all occurences of col1 with "Column Name".

insertendrow(string) inserts contents of string at the end of specified row.
Eg: insertendrow(4 "\hline") inserts at the end of the 4th row a \hline.
The string is inserted after the "\\" indicating a new line.
If an entire new row is added, the row delimiter has to be added as well.
Note: If used with append, the number correspond to the row of the final table, including headers.

coldelimiter(string)/rowdelimiter(string) sets delimiter for columns (standard "&") and rows (standard "\\").

coefficient(options) Allows to add significance stars to the coefficients and parenthesis around standard errors.
Without specifying any options, the entire mata matrix is treated as a matrix with coefficients on the uneven rows (1,3,...) and standard errors on the even rows (2,4,..).
For example:

b(1,1) b(1,2)
se(1,1) se(1,2)
b(2,1) b(2,2)
se(2,1) se(2,2)

where se(1,1) is the standard error of the estimated coefficient b(1,1).

The levels for the significance starts are then 10%, 2 stars for 5% and 3 stars for 1%, basing on a two sided T-Test with a degree of freedom of 999.
The standard errors are put in parenthesis.
For example, significance stars are only added to b(2,1) and b(2,2), then the options would be pos((3,1) (4,2)).

Alternative settings can be specified in the options, which are:

Option Description

dof(number) sets the degree of freedom for the twosided t-test.
par standard errors in parenthesis.
pos(cell range) specifies that only a sub matrix is recognized containing estimated coefficients.
The order is pos(r1,c1) (r2,c2), where (r1,c1) are the upper left coordinates of the sub matrix, while (r2,c2) are the lower right coordinates.

show displays output.

Example

mata test1 = (1,0.2,3\4,0.05,6)

mata test2 = (7,8,9\10,11,12)

Save matrix "test1" as test.tex, assign row and column names and add a title (run the locals first).

local colrow_names "rownames(row1 row2) colnames(col1 col2 col3)"

local headers `"preheader("\hline \multicolumn{@M}{|l|} \\ \hline")"'

local substitute `"substitute(row1 "1st Row" row2 "2nd Row" col1 "Column 1" col2 "Column 2" col3 "Column 3")"'

mmat2tex test1 using test.tex , replace `colrow_names' `substitute'

Append table with matrix "test2" and add an additional row between 3th and 4th row of the final table.

local col_subst `"rownames(row3 row4) substitute(row3 "3th Row" row4 "4th Row" )"'

local inserted `"insertendrow(5 "\multicolumn{@M}{|l|} \\") bottom("End of Table")"'

mmat2tex test2 using test.tex , append `col_subst' `inserted'

Add signficance stars to the 2nd and 3rd column of "test1" and add parenthesis around the standard errors (2nd row).
Set the significance levels as 5%, 1% and 0.1%

mmat2tex test1 using test.tex , replace coefficients(pos((1,2) (2,3)) par level(0.05,0.01,0.001))

Specify format %12.0f for the first column and %12.9g for the remaining ones.

mmat2tex test1 using test.tex , replace fmt("%12.0f %12.9g")

Include Latex command for a complete Table.

mmat2tex test1 using test.tex , replace rownames(row1 row2) colnames(col1 col2 col3) preheader("\begin \begin{|l|.|.|.|}\hline \hline") bottom("\end \end")

Author

Jan Ditzen (Heriot-Watt University)

Email: jd219@hw.ac.uk

Web: www.jan.ditzen.net

The substitution routine is gratefully taken from Benn Jan's estout command. Thanks to Nick Cox for his suggestion to use local macros for the examples. Any remaing errors are my own.

Also see

See also: estout, outreg, outreg2