*! version 10.0 29aug2023

texresults2 Improved version of texresults to create external file of LaTex macros with results

Syntax

texresults2 using , textmacro(macroname) []

Description

texresults2 The original Texresults command was created by Alvaro Carril to store results computed in Stata as Latex macros in a text file. The external text file can be used in LaTeX to to reference results by their macro.

As noted by Carril "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 updates 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 situation 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."

While the original texresults was very helpful, tesresults2 improves upon some bugs and adds functionality. First, due to the use of the round command in the original texresults program, occasionally an error is produced where stata is unable to correctly hold and format certain decimal results. Texresults2 fixes this error by converting results to a string format and using associated stata formatting rules before exporting.

The original texresults only had functionality to export p-values when estimation commands relied on a t-distribution to calculate said p-values (IE Ordinary Least Squares regression). Texresults2 builds out this functionality to include exporting pvalues calculate with a z-distribution (IE Logit or Probit regressions). Texresults2 also includes the ability to directly export the upper and lower bound values for a 95% confidence interval around an estimation.

Options

Result - options mutually exclusive

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 (calculated using a t-stat) to be stored in macroname

pvaluez(varname) p-value (calculated using a z-stat) to be stored in macroname

lb(varname) lower bound of a 95% confidence interval (calculated using a t-stat to) be stored in macro name

ub(varname) upper bound of a 95% confidence interval (calculated using a t-stat to) be stored in macro name

lbz(varname) lower bound of a 95% confidence interval (calculated using a z-stat to) be stored in macro name

ubz(varname) upper bound of a 95% confidence interval (calculated using a z-stat to) be stored in macro name

File

textmacro(macroname) name of new LaTeX macro (without backslash) - required

replace Replace filename

append Append filename

Formatting

round(real) round to the number of decimal places specified by the given integer.

Examples

Setup (OLS)

. sysuse auto

. regress mpg trunk weight foreign

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

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

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

. texresults2 using results.txt, texmacro(forgiencoef) coef(foreign) round(1) append

Append the values of the lower bound of the 95% confidence interval for the foreign coefficient macro to "results.txt", rounded to 3 decimal digits. The created macro is "\lbforgien":

. texresults2 using results.txt, texmacro(lbforgien) lb(foreign) round(3) append

Setup (Logit)

. Logit foreign trunk weight mpg

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

. texresults2 using results.txt, texmacro(trunkcoef) coef(trunk) round(1) append

Append the values of the lower bound of the 95% confidence interval for the foreign coefficient macro to "results.txt", rounded to 3 decimal digits. The created macro is "\lbtrunk:" Note the use of the lbz option because inference with logit regressions operates using a z distribution.

. texresults2 using results.txt, texmacro(lbtrunk) lbz(trunk) round(3) append

Text Document Produced

\newcommand{\rmse}{$3.42$}
\newcommand{\forgiencoef}{$-1.6$}
\newcommand{\lbforgien}{$-3.762$}
\newcommand{\trunkcoef}{$0.0$}
\newcommand{\lbtrunk}{$-0.195$}