*! version 0.31

Title

matprint -- Printing and styling a Stata matrix

Syntax

matprint matrixname [using] [, options]

Main
style(string) Style for output. One of the values smcl (default),
csv (semicolon separated style),
latex or tex (latex style),
html (html style) and
md (markdown style)

decimals(string) Matrix of integers specifying numbers of
decimals at cell level. If the matrix is smaller than the data matrix the right
most column is copied to get the same number of columns.
And likewise for the bottom row

caption(string) Caption for the output. Same as title

title(string) Title for the output. Same as caption.
title overwrites caption

top(string) String containing text prior to table content.
Default is dependent of the value of the style option

undertop(string) String containing text between header and table
content.
Default is dependent of the value of the style option

bottom(string) String containing text after to table content.
Default is dependent of the value of the style option

replace Delete an existing using file before adding table

noeqstrip Do not remove duplicate successive roweq or coleq values

nozero Do not show zeros in output

hidesmall(integer) If set hide all values below the set value.
Default is the value 0, ie no hidding

nocleanmata For debugging. Do not delete Mata values and instances

version 13 and up
toxl(string) A string containing up to 5 values separated
by a comma. The values are:

* path and filename on the excel book to save in. Excel book suffix is set/reset to xls for Stata 13 and to xlsx for Stata 14 and above

* the sheet name to save output in

* (Optional) replace - replace/overwrite the content in the sheet

* (Optional) row, column numbers for the upper right corner of the table in the sheet

* (Optional) columnn widths in parentheses. If more columns than widths the last column width is used for the rest

todocx(string) A string containing one or two values separated
by a comma. The values are:

* path and filename on the excel book to save in.

* (Optional) replace - replace/overwrite the content in the sheet

Description

matprint prints and styles a matrix in text. The styles can be smcl
for nice outlook in the log (and when eg saved in the using file the output can
be used in smcl documentation files), csv for a semicolon separated output
html, tex/latex and md (markdown).

The styles can be added non standard style code pre table (option top),
post header (option undertop) and post table (option bottom).

A title/caption for the table can be added as well as a column title for roweq
names (option rowtitle1)

Number of decimals can be set at cell level in option decimals by
specifying a matrix of integers.

If the decimal matrix is smaller than the data matrix first the right most
column of integers are copied and then the bottom row is also copied to get the
same size.

If the decimal matrix is too big only the top left part of the decimals numbers
matching the size of the data matrix is used.

matprint has the concept of styles (for smcl, html, tex/latex, md for
markdown and csv) and a simple setting of decimals.

matprint can be used to export the content to Excel and saved in named
sheets using the option toxl.

matprint is highly integrated with log2markup such that
a matrix in a layout of eg html or latex can be merged to the final document
generated by log2markup in the same style as the end document.

Examples

Below is a set of examples. You can copy the code and insert it in the
command window or you can just click once on each blue line below.

Then the command is automatically moved to the command window and executed.

Note that there is progression in the examples such a command line may require
some of the previous lines to show the intended properly.

In this example estimates and their confidence intervals for two regression
models are combined into one summary matrix

`"sysuse auto ,clear"'

First regession and matrix part b1:

`"regress price mpg turn weight"'

`"matrix b1 = r(table)"'

`"matrix b1 = b1["b", 1...] \ b1["ll".."ul", 1...]"'

`"matrix roweq b1 = M1"'

Second regession and matrix part b2:

`"regress price gear_ratio mpg foreign"'

`"matrix b2 = r(table)"'

`"matrix b2 = b2["b", 1...] \ b2["ll".."ul", 1...]"'

`"matrix roweq b2 = M2"'

Combine the two regression summaries using mat_rapp:

`"mat_rapp b12 : b1 b2, miss(.) cons"'

matrix b12 = b12'

To see the matrix in the log window in smcl style and 3 decimals for the
first column and 2 decimals for the rest

`"matprint b12, title(Regression summary table) decimals((3, 2))"'

Sometimes eg when using log2markup (if installed) it is
preferred that the output in the log is in latex/tex or html like below:

`"matprint b12, title(Regression summary table) decimals(3) style(html)"'

The table output can also be saved in a file in the current directory:

`"matprint b12 using table_b12.tex, title(Regression summary table) decimals(3) style(tex)"'

The table output can be saved in sheet "b12" at the Excel workbook
"tbls.xls(x)" in the current directory:

`"matprint b12, title(Regression summary table) decimals(3) toxl(tbls, b12)"'

To see current directory:

cd

To see the Excel workbook (stata 13):

shell tbls.xls

To see the Excel workbook (stata 14 and up):

shell tbls.xlsx

The table output can be saved in Word document "tbl.docx" in the
current directory:

`"matprint b12, title(Regression summary table) decimals(3) todocx(tbl, replace)"'

To see the Word document (One can not add several tables to the same Word file):

shell tbl.docx

Show replicated roweq and coleg values:

`"matprint b12, noeqstrip"'

Hide values less than 5:

`"matprint b12, hidesmall(5)"'

Authors and support

Author:

Niels Henrik Bruun,

Aalborg University Hospital

Support:

niels.henrik.bruun@gmail.com