{smcl}
{* *! version 0.31}{...}
{vieweralsosee "" "--"}{...}
{vieweralsosee "Help matlist" "help matlist"}{...}
{vieweralsosee "Help log2markup (if installed)" "help log2markup"}{...}
{vieweralsosee "Help sumat (Is installed with matprint" "help sumat"}{...}
{vieweralsosee "Help estout (if installed)" "help estout"}{...}
{vieweralsosee "Help mat2txt (if installed)" "help mat2txt"}{...}
{vieweralsosee "Help outtable (if installed)" "help outtable"}{...}
{viewerjumpto "Syntax" "matprint##syntax"}{...}
{viewerjumpto "Description" "matprint##description"}{...}
{viewerjumpto "Examples" "matprint##examples"}{...}
{viewerjumpto "Author and support" "matprint##author"}{...}
{title:Title}
{phang}
{bf:matprint} {hline 2} Printing and styling a Stata matrix
{marker syntax}{...}
{title:Syntax}
{p 8 17 2}
{cmdab:matprint} matrixname [{help using}] [{cmd:,} {it:options}]
{synoptset 20 tabbed}{...}
{synopthdr}
{synoptline}
{syntab:Main}
{synopt:{opt s:tyle(string)}}Style for output. One of the values {bf:smcl} (default),
{bf:csv} (semicolon separated style),
{bf:latex or tex} (latex style),
{bf:html} (html style) and
{bf:md} (markdown style)
{p_end}
{synopt:{opt d:ecimals(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{p_end}
{synopt:{opt cap:tion(string)}}Caption for the output. Same as {opt ti:tle}{p_end}
{synopt:{opt ti:tle(string)}}Title for the output. Same as {opt cap:tion}.
{opt ti:tle} overwrites {opt cap:tion}{p_end}
{synopt:{opt to:p(string)}}String containing text prior to table content.
Default is dependent of the value of the style option{p_end}
{synopt:{opt u:ndertop(string)}}String containing text between header and table
content.
Default is dependent of the value of the style option{p_end}
{synopt:{opt b:ottom(string)}}String containing text after to table content.
Default is dependent of the value of the style option{p_end}
{synopt:{opt r:eplace}}Delete an existing {help using:using} file before adding table{p_end}
{synopt:{opt noe:qstrip}}Do not remove duplicate successive roweq or coleq values{p_end}
{synopt:{opt noz:ero}}Do not show zeros in output{p_end}
{synopt:{opt h:idesmall(integer)}}If set hide all values below the set value.
Default is the value 0, ie no hidding{p_end}
{synopt:{opt noc:leanmata}}For debugging. Do not delete Mata values and instances{p_end}
{synopthdr:version 13 and up}
{synopt:{opt toxl:(string)}}A string containing up to 5 values separated
by a comma. The values are:{break}
* path and filename on the excel book to save in. Excel book suffix is set/reset to {cmd:xls} for Stata 13 and to {cmd:xlsx} for Stata 14 and above{break}
* the sheet name to save output in{break}
* (Optional) replace - replace/overwrite the content in the sheet{break}
* (Optional) row, column numbers for the upper right corner of the table in the sheet{break}
* (Optional) columnn widths in parentheses. If more columns than widths the last column width is used for the rest
{p_end}
{synopt:{opt todocx:(string)}}A string containing one or two values separated
by a comma. The values are:{break}
* path and filename on the excel book to save in.{break}
* (Optional) replace - replace/overwrite the content in the sheet{break}
{p_end}
{synoptline}
{p2colreset}{...}
{p 4 6 2}
{marker description}{...}
{title:Description}
{pstd}
{cmd:matprint} prints and styles a matrix in text. The styles can be {help smcl: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).
{pstd}
The styles can be added non standard style code pre table (option {opt to:p}),
post header (option {opt u:ndertop}) and post table (option {opt b:ottom}).
{pstd}
A title/caption for the table can be added as well as a column title for roweq
names (option {opt r:owtitle1})
{pstd}
Number of decimals can be set at cell level in option {opt d:ecimals} by
specifying a matrix of integers. {break}
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.{break}
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.
{pstd}
{cmd:matprint} has the concept of styles (for smcl, html, tex/latex, md for
markdown and csv) and a simple setting of decimals.
{pstd}
{cmd:matprint} can be used to export the content to Excel and saved in named
sheets using the option {opt toxl:}.
{pstd}
{cmd:matprint} is highly integrated with {help log2markup: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.
{marker examples}{...}
{title:Examples}
{pstd}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.{break}
Then the command is automatically moved to the command window and executed.{p_end}
{pstd}Note that there is progression in the examples such a command line may require
some of the previous lines to show the intended properly.{p_end}
{pstd}In this example estimates and their confidence intervals for two regression
models are combined into one summary matrix{p_end}
{phang}{stata `"sysuse auto ,clear"'}{p_end}
{phang}First regession and matrix part b1:{p_end}
{phang}{stata `"regress price mpg turn weight"'}{p_end}
{phang}{stata `"matrix b1 = r(table)"'}{p_end}
{phang}{stata `"matrix b1 = b1["b", 1...] \ b1["ll".."ul", 1...]"'}{p_end}
{phang}{stata `"matrix roweq b1 = M1"'}{p_end}
{phang}Second regession and matrix part b2:{p_end}
{phang}{stata `"regress price gear_ratio mpg foreign"'}{p_end}
{phang}{stata `"matrix b2 = r(table)"'}{p_end}
{phang}{stata `"matrix b2 = b2["b", 1...] \ b2["ll".."ul", 1...]"'}{p_end}
{phang}{stata `"matrix roweq b2 = M2"'}{p_end}
{phang}Combine the two regression summaries using {help mat_rapp:mat_rapp}:{p_end}
{phang}{stata `"mat_rapp b12 : b1 b2, miss(.) cons"'}{p_end}
{phang}{stata "matrix b12 = b12'"}{p_end}
{phang}To see the matrix in the log window in smcl style and 3 decimals for the
first column and 2 decimals for the rest{p_end}
{phang}{stata `"matprint b12, title(Regression summary table) decimals((3, 2))"'}{p_end}
{phang}Sometimes eg when using {help log2markup:log2markup (if installed)} it is
preferred that the output in the log is in latex/tex or html like below:{p_end}
{phang}{stata `"matprint b12, title(Regression summary table) decimals(3) style(html)"'}{p_end}
{phang}The table output can also be saved in a file in the current directory:{p_end}
{phang}{stata `"matprint b12 using table_b12.tex, title(Regression summary table) decimals(3) style(tex)"'}{p_end}
{phang}The table output can be saved in sheet "b12" at the Excel workbook
"tbls.xls(x)" in the current directory:{p_end}
{phang}{stata `"matprint b12, title(Regression summary table) decimals(3) toxl(tbls, b12)"'}{p_end}
{phang}To see current directory:{p_end}
{phang}{stata cd}{p_end}
{phang}To see the Excel workbook (stata 13):{p_end}
{phang}{stata shell tbls.xls}{p_end}
{phang}To see the Excel workbook (stata 14 and up):{p_end}
{phang}{stata shell tbls.xlsx}{p_end}
{phang}The table output can be saved in Word document "tbl.docx" in the
current directory:{p_end}
{phang}{stata `"matprint b12, title(Regression summary table) decimals(3) todocx(tbl, replace)"'}{p_end}
{phang}To see the Word document (One can not add several tables to the same Word file):{p_end}
{phang}{stata shell tbl.docx}{p_end}
{phang}Show replicated roweq and coleg values:{p_end}
{phang}{stata `"matprint b12, noeqstrip"'}{p_end}
{phang}Hide values less than 5:{p_end}
{phang}{stata `"matprint b12, hidesmall(5)"'}{p_end}
{marker author}{...}
{title:Authors and support}
{phang}{bf:Author:}{break}
Niels Henrik Bruun, {break}
Aalborg University Hospital
{p_end}
{phang}{bf:Support:} {break}
{browse "mailto:niels.henrik.bruun@gmail.com":niels.henrik.bruun@gmail.com}
{p_end}