UCLA Academic Technology Services HomeServicesClassesContactJobs
Stat Computing > Stata > Stata Tools for LaTeX
Search

List Variables in LaTeX

Currently, there are a couple of Stata programs that will generate LaTeX code for listing observations of a variable list. We will focus on Stata command listtex here. You can use Stata's findit command to download the program from the internet. Please see our webpage on how to use findit to search for programs and additional help for more details.

Example 1:

In this example, we are going to show how to create a text file containing the LaTeX code for creating a nice table layout for listing variables.  

use http://www.ats.ucla.edu/stat/stata/notes/hsb2, clear
(highschool and beyond (200 cases))
list  write read math ses if female ==0 & prog ==1 
     +------------------------------+
     | write   read   math      ses |
     |------------------------------|
  7. |    44     44     39      low |
 25. |    41     42     43      low |
 27. |    52     57     41      low |
 32. |    59     55     63      low |
 41. |    49     42     43      low |
     |------------------------------|
 44. |    49     63     49      low |
 45. |    44     52     49      low |
 50. |    57     57     60   middle |
 94. |    59     50     42   middle |
100. |    44     44     61   middle |
     |------------------------------|
101. |    49     63     35   middle |
102. |    39     55     57   middle |
111. |    59     68     58   middle |
118. |    57     63     54   middle |
119. |    33     34     41   middle |
     |------------------------------|
138. |    44     44     46   middle |
141. |    31     42     57   middle |
145. |    65     60     58     high |
178. |    65     65     48     high |
188. |    33     44     54     high |
     |------------------------------|
190. |    59     68     56     high |
     +------------------------------+

we want to put the above output from the list command to a LaTeX file. Here is the syntax for listtex to generate the LaTeX code to a text file, called list1.tex.

#delimit ;
listtex write read math ses if female ==0 & prog ==1 using list1.tex,
rstyle(tabular) head("\begin{tabular}{rrrr}""
\textit{Write} &\textit{Read}&\textit{Math}&\textit{Ses}\\\\")
foot("\end{tabular}");

Let's take a look at some of the options following the listtex command. The "rstyle" option stands for "row style" in the output. For example, if we want to create a LaTeX table environment, then rstyle will be set to be tabular. If we want to create a plain TeX table environment, then rstyle will be set to be halign. The head and foot options enable us to add LaTeX's table environment before and after the table rows in the output. All these options are required for creating a  table of LaTeX style.  

After the command, a text file called list1.tex will be created. We can then use LaTeX command \input to include  it in a LaTeX file. Here is the LaTeX file for creating a page of listed variables and here is the pdf version of it.

Example 2:

Instead of creating a text file containing the LaTeX code, listtex also allows us to output the LaTeX code to Stata Results Window. We can then simply copy and paste the code to a LeTeX file. For the same output, we can now do the following:

#delimit;
listtex write read math ses if female ==0 & prog ==1 ,
type rstyle(tabular)
head("\begin{tabular}{rrrr}""\textit{Write}
&\textit{Read}&\textit{Math}&\textit{Ses}\\\\")
foot("\end{tabular}");

\begin{tabular}{rrrr}
\textit{Write} &\textit{Read}&\textit{Math}&\textit{Ses}\\\\
52&57&41&low\\
33&44&54&high\\
59&50&42&middle\\
57&63&54&middle\\
49&42&43&low\\
57&57&60&middle\\
39&55&57&middle\\
49&63&35&middle\\
44&52&49&low\\
31&42&57&middle\\
65&60&58&high\\
41&42&43&low\\
65&65&48&high\\
59&55&63&low\\
44&44&61&middle\\
44&44&39&low\\
33&34&41&middle\\
44&44&46&middle\\
59&68&58&middle\\
59&68&56&high\\
49&63&49&low\\
\end{tabular}

After the command, we will simply copy and paste the LaTeX code to our LaTeX file. Here is the LaTeX file for creating a page of listed variables and here is the pdf version of it.


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California