### Stata Graph in LaTeX

Stata command graph2tex is a user-written command that does two things after a Stata graph command. It first generates a .eps file corresponding to your graph and then generate LaTeX code to be included in a LaTeX file where the graph is to be displayed. You can download graph2tex from within Stata using the findit command by typing findit graph2tex (see How can I use the findit command to search for programs and get additional help? for more information about using findit).

Example 1: Including a scatter plot in a LaTeX file

use http://www.ats.ucla.edu/stat/stata/notes/hsb2, clear
(highschool and beyond (200 cases))
scatter read write
graph2tex, epsfile(readwrite)
\begin{figure}[h]
\begin{centering}
\end{centering}
\end{figure}
pwd
d:\stata2latex
The last command is for to know where the eps file is located. It is usually a very good idea to put the LaTeX file where the .eps file is going to be included and the eps file in the same directory. Here is a simple LaTeX file that will contain the plot generated above. Here is the pdf file corresponding to it.

Example 2: More options

We can change the size of the graph by using the option ht. For example, we will produce a graph of 5 inches in height, rather 3 inches as the default. Also, we can produce a caption for the plot by using the caption option.

graph2tex, epsfile(rw2) ht(5) caption(Reading and Writing Scores)
% exported graph to rw2.eps
\begin{figure}[h]
\begin{centering}
\includegraphics[height=5in]{rw2}
\end{centering}
\end{figure}

Here is a LaTeX file containing the graph and the pdf file corresponding to it.

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.