|
|
|
||||
|
|
|||||
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)
% exported graph to readwrite.eps
\begin{figure}[h]
\begin{centering}
\includegraphics[height=3in]{readwrite}
\end{centering}
\end{figure}
pwd d:\stata2latexThe 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}
\caption{Reading and Writing Scores}
\end{centering}
\end{figure}
Here is a LaTeX file containing the graph and the pdf file corresponding to it.
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