*! version 1.1 04apr2017

Title

texresults -- Create external file of LaTeX macros with results

Syntax

texresults using filename,
[options]

Result^
result(real) specify any result to be stored in macroname; see Result below

coef(varname) coefficient to be stored in macroname

se(varname) standard error to be stored in macroname

tstat(varname) t-stat to be stored in macroname

pvalue(varname) p-value to be stored in macroname

File
* texmacro(macroname) name of new LaTeX macro (without backslash)

replace replace filename

append append new result to filename

Formatting
round(real) round result in units of real; see round()

unitzero add a zero to the units digit if abs(result)<1 (e.g. -0.6 instead of -.6)

* texmacro(macroname) is required.

^ options in this category are mutually exclusive.

varname may contain factor variables; see fvvarlist.

Description

texresults is a convenience command to easily store any computed result to a LaTeX macro.
After running an estimation command in Stata, texresults can be used to create a new LaTeX macro, which is stored in an external text file.
This file may be called from a LaTeX document in order to use those results.

One of the main advantages of a Stata/LaTeX workflow is the automatic updating of tables and figures.
For instance, if we add a new control variable to a regression, we can correct the do-file that produces a table of coefficients and compile the LaTeX document again to see the updated table.
However, that advantage doesn't extend to in-text mentions of coefficients (or other results).
This leads to documents that contain inconsistent results, which have to be manually checked every time a preliminary result changes.

This sitation can be remedied by creating an external file with LaTeX macros that store all cited results of an analysis.
Using these macros instead of manually copying results in the text is much less error prone, and we can be certain that results are consistent throughout the document.

Options

Result

The most general option for storing results is by using result(real), which allows for any numeric input.
Alternatively, coef, se, tstat and pvalue are convenience options that may be used to directly access (or compute) estimated coefficients, standard errors, t-stats or p-values respectively.

Options in this category are mutually exclusive (only one must be specified):

result(real)
adds any real number to macroname, including scalars, locals or matrix elements.
It can be used in post estimation.
For instance, consider the following setup:

. sysuse auto

. regress mpg trunk weight foreign

We can use result(e(r2)) to add the computed R-squared and result(_b[foreign]) to add the estimated coefficient for foreign.
However, for adding coefficients it may be easier to use coef(varname) (see below).

coef(varname)
includes varname's coefficient in the LaTeX macro.
For example, considering the same setup as in result(real), we can use coef(foreign) to add the coefficient of foreign.

se(varname)
includes varname's standard error in the LaTeX macro.
For example, considering the same setup as in result(real), we can use se(foreign) to add the standard error of foreign.

tstat(varname)
includes varname's t-stat in the LaTeX macro.
For example, considering the same setup as in result(real), we can use tstat(foreign) to add the t-stat of foreign.

pvalue(varname)
includes varname's p-value in the LaTeX macro.
For example, considering the same setup as in result(real), we can use pvalue(foreign) to add the p-value of foreign.

File

texmacro(macroname) will save the specified result in a LaTeX macro with name macroname, automatically appending an initial backslash.
For example, the option macroname(weirdresult) will create the LaTeX macro \weirdresult, which will print the specified result when used in a LaTeX document.

texresults will issue a warning if macroname is not a valid LaTeX macro, that is, if it doesn't contain only uppercase and lowercase alphabetical characters (assuming new macros don't consist of a single non-alphabetical character).

replace will replace all contents in filename with a new LaTeX macro; see [P] file.

append will append the new LaTeX macro to the end of filename; see [P] file.

Formatting

round(real) will round the result in units of real; see round(). By default all results will be rounded to 2 decimal digits, that is, round(0.01).
So if the specified result is 1.082598, it will be displayed as 1.08.

If you don't want to apply any rounding, use round(0).

unitzero will add a zero to the units digit if abs(result)<1, which is usually preferred in text.
For example, a coefficient whose value is -.6 will be stored as -0.6.

Examples

Stata setup

. sysuse auto

. regress mpg trunk weight foreign

Store root MSE of model in "results.txt", rounded by default to 2 decimal digits (default), with macro name "\rmse":

. texresults using results.txt, texmacro(rmse) result(e(rmse))

Append foreign coefficient macro to "results.txt", rounded to 1 decimal digit. The created macro is "\mainresult":

. texresults using results.txt, texmacro(mainresult) coef(foreign) append

Append trunk standard error with macro name "\trunkSE", adding a zero to unit digit:

. texresults using results.txt, texmacro(trunkSE) se(trunk) unitzero append

LaTeX document:

\documentclass

\input

\begin

The model's root MSE is \rmse,

foreign coefficient is \mainresult, and

trunk standard error is \trunkSE.

\end

Author

Alvaro Carril

Research Analyst at J-PAL LAC

acarril.github.io

acarril@fen.uchile.cl

Acknowledgements

The creation of this program arose out of necessity, as me and a team of other RAs needed a way to streamline the inclusion of results in paper drafts.
This team includes Andre Cazor, Raul Duarte, Maximiliano Garcia, João Marcos Garcia, Shanon Hsu, Jemimah Muraya, Nikolai Schaffner and Jose Vila-Belda.
I thank them all for their valuable feedback and continuous (long distance) support.