outreg_latex

Version 1.2.0.0 (48 KB) by Rob
Generates latex table code for regression and other output useful for journal articles.
970 Downloads
Updated 5 Feb 2014

View License

Function outreg_latex.m written by
Rob Hicks
Department of Economics
The College of William and Mary

This function is an implementation of some of the features of the
ado routines outreg and outreg2 found in stata. The stata routines makes it
easy to put statistical results into a latex table. This function tries
to do the same in matlab.

Given the structs results,names,more_results,more_results_names
this function prints standard regression output for journal articles in
latex format for easy incorporation into your latex document.

Models are placed as columns in the table with standard errors for each
variable in results put in parenthesis below the coefficient estimate.
Significance results are p<=.05 is ** and .05<p<=.1 is *. These are
not user definable at present.

The function also adds metadata as comments preceding your table code
(name and path of calling function and outreg_latex.m and the date).
I find this information useful to include in the tex document for going
back to replicate results after some time has passed.

To be assured of proper tex table syntax be sure to copy from the
matrix/cell view (click on the cell in the matlab workspace window) and
copy the code from there. Unfortunately matlab surrounds each line of tex
code with '. Remove these from within your tex document.

****
Remember to remove the ' character at the beginning and end of each line
after you paste the copied code into your tex document.
****

The sample file 'sample_frontend.m' demonstrates most of the
functionality.

Notes:

1. You will need to create the following matlab structures/matrices/cells:
A. The structure results contains:
M matrices (one for each of M models) with variables in rows with
the following columns: parameter estimate, standard error,
perhaps other columns of data, and the p-value in the final
column.
-The matrices comprising the structure results need not be of the
same dimension.
-The function works if M=1 (you only want to build a table for
one model).
B. The structure names contains:
M cells containing variable names for each row of each corresponding matrix found
in results. The variable names need not be the same across the M
models. However, this function uses these variable names to
match results across columns, so take care in labeling your
variables appropriately.
-Variable names given in names and more_results_names should be latex
compliant (e.g. my_variable_name is not latex compliant, use
my\_variable\_name instead. R^2 is not latex compliant, whereas $R^2$
is.)
C. The structure more_results contains:
M vectors containing model statistics that do not have standard
errors.
-e.g., sample size, r-squared, chi-squared stats. If you need to
include standard errors, include the parameters of interest in results!!!
D. The structure more_results_names contains:
M cells with variable names for each row of each matrix in the
structure more results.
-Again, make your names latex compliant
-Again, you may have different statistics/names for each of the M
models, but when building the table, matching occurs by name.
E. The cell model_names contains column headers for your table:
An M x 1 cell containing model names as text. To use generic model
names (Model 1, Model 2, etc.) set model_names=[].
F. The cell, table_opts (1 x 1) contains one of the following latex
table environment variables: table, longtable,
sidewaystable (not yet tested)

2. The function matches results across models by common variable names
and sorts them alphabetically. At present there is no sort order
capability. A crude way to order your results is to include a leading
integer value (e.g. variable Z becomes variable 1Z if you want Z to
appear first in the table) and then remove these in your latex
document before the final compilation of the pdf.

3. At present there is no multicolumn or other fancy functionality.

4. At present there is no error checking. If, for example, the
dimensions of names is different from results for a model this code
will crash. If you get crashes, check your input structs to make
sure it is in line with the requirements set out above.

Cite As

Rob (2024). outreg_latex (https://www.mathworks.com/matlabcentral/fileexchange/38564-outreg_latex), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.2.0.0

Removed references to custom function rows() and replaced with matlab built-in function size().

1.0.0.0