Include Stata figures in Latex

Just found an easy way to include figures from Stata into Latex by converting Stata-figures to PDF-files first. Just use the following codes:

global infile="FOLDER_TO_SAVE_FIGURES"
gr export "$infile/FILENAME.eps", as(eps) preview(off) replace
!epstopdf "$infile/FILENAME.eps"

That saves FILENAME.pdf into folder defined in the global infile (most probably MikTex needs to be installed for that).

In Latex, simply use the following code:


3 thoughts on “Include Stata figures in Latex

  1. I think you can also change the size and direction of the figure in the example:


    is the crucial aspect. In Jan’s example repeated here, it gives a height of the figure of 5 inches (roughly 12.5 cm), and the width is probably scalled prportionally.
    The angle looks like the figure was turned 90 degrees (from normal to landscape so to speak), you might prefer leaving this out. But I am looking forward to those that try this empirically.

    — Ben

  2. Using your method I get the Helvetia font face on my graphs that is hard to change. This problem is not there when I directly export the graph as a pdf, see code below. Is there an advantage of using eps first and afterward convert the eps file to pdf?

    graph export “$infile/StartAgeNew.pdf”, as(pdf) replace

    Anyways, thank you for showing the way.

    – Simon

  3. Nowadays I usually also directly export to pdf using the same code that you use. I remember that I used the more lengthy code years ago because of the orientation of the figure (which – for whatever reason – was wrong with the one-line code). I’m not sure why the font type changes though.

Leave a Reply