/*
cd "C:/Users/au24026/Documents/STATA/StataHacks/docs/My commands/matprint"
use low-bwt using "http://www.stata-press.com/data/r12/hospid2.dta
label data "From: http://www.stata-press.com/data/r12/hospid2.dta"
saveold hospid2, replace version(12)
*/
/***
# What is -matprint-
The command -matprint- is for styling and printing Stata matrices.
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.
The command -matprint- is a mix of matlist and if installed estout for matrices.
The command -matlist- to me is too detailed with respect to controlling the
smcl output and too little detailed with respect to styles.
The command -estout- has the concept of styles and a simple setting of decimals.
However presenting and styling matrices is not the main focus.
And also here there are too much functionality.
-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.
-matprint- is a part of the package matrixtools.
## Syntax
The syntax is: `matprint matrixname [using] [, options]`
Here "matrixname" is the matrix to print and/or style.
The styled matrix can be save as file using the using modifier.
## Options
* **s**tyle(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)
* **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
* **ti**tle(string): Title/caption for the matrix output
* **to**p(string): String containing text prior to table content. Default is
dependent of the value of the style option
* **u**ndertop(string): String containing text between header and table content.
Default is dependent of the value of the style option
* **b**ottom(string): String containing text after to table content.
Default is dependent of the value of the style option
* **r**eplace: Delete an existing using file before adding table
* **noe**qstrip: Do not remove duplicate successive roweq or coleq values
* **h**idesmall(integer): If set hide all values below the set value.
Default is the value 0, ie no hidding
## Versions
-matprint- is tested in version 12.1 ic, 13.1 ic, 14.2 ic, and 15.1 ic.
## Installation
To install use the command: `ssc install matrixtools`
# A demonstration of -matprint-
## The example data
We use a subset of the Stata hospid2 dataset:
`use low-bwt using "http://www.stata-press.com/data/r12/hospid2.dta", clear`
***/
//OFF
use hospid2, clear
//ON
metadata *
/***
## Presenting OR estimates and CI from 2 regressions
Do the first regression, select OR estimates and CI for all explanatory
variables, and set roweq for the result to M1:
***/
/**/logit low age lwt smoke ptl ht ui ftv, or nolog cformat(%6.3f)
/**/mat b1 = r(table)
/**/mat b1 = b1["b", "low:age".."low:ftv"] \ b1["ll".."ul", "low:age".."low:ftv"]
/**/mat roweq b1 = M1
/***
And the same for a reduced model (no age and ftv):
***/
/**/logit low lwt smoke ptl ht ui, or nolog cformat(%6.3f)
/**/mat b2 = r(table)
/**/mat b2 = b2["b", "low:lwt".."low:ui"] \ b2["ll".."ul", "low:lwt".."low:ui"]
/**/mat roweq b2 = "M2"
/***
Stata has a command -mat_rapp- that merges matrices on rownames:
***/
/**/mat_rapp b12 : b1 b2, miss(.) cons
/***
The merged matrix is transposed:
***/
mat b12 = b12'
/***
Now the results can be presented by matprint:
***/
matprint b12, title(Regression summary table) decimals(3) replace
/***
The table can be saved in a file in smcl format:
***/
matprint b12 using Reg_sum_tbl.smcl, title(Regression summary table) d(3) replace
/***
[The saved file can be seen here](Reg_sum_tbl.smcl)
The table can be saved in a file in html format (MkDocs overrules code output
here and show html as html):
***/
matprint b12 using Reg_sum_tbl.html, title(Regression summary table) d(3) style(html) replace
/***
[The saved file can be seen here](Reg_sum_tbl.html)
The table can be saved in a file in latex format:
***/
matprint b12 using Reg_sum_tbl.tex, title(Regression summary table) d(3) style(tex) replace
/***
[The saved file can be seen here](Reg_sum_tbl.tex)
The table can be saved in a file in pandoc markdown format:
***/
matprint b12 using Reg_sum_tbl.md, title(Regression summary table) d(3) style(md) replace
/***
[The saved file can be seen here](Reg_sum_tbl.md)
***/
*matprint b12, noe h(9)