Stata for Mac PDF and “set graphics on”

May 16, 2011 at 4:14 am 4 comments

| Gabriel |

I recently noted that graph exporting to PDF in Stata for Mac is fixed. Turns out that this is only partially true. It works and creates beautiful output, but unlike the other “graph export” options it only works if you have “set graphics on” in the Stata GUI. If you’re running it as Stata console or have graphics set off in Stata GUI, it simply doesn’t work. (I do this when batching a lot of graphs as it is faster and less distracting).

My understanding is that this has something to do with how Stata relies on Mac’s Quartz driver to render PDF so it’s not really feasible to fix. So basically you have three options:

1) Do it in the GUI with “set graphics on” and accept the CPU performance hit and distraction of all the graphs rendering.

2) Use my graphexportpdf ado file or the “graph print” command with CUPS-PDF as the print driver.

3) Stick to using EPS

Entry filed under: Uncategorized. Tags: , .

Lyx 2.0 Life Imitates AJS


  • 1. jpferguson  |  May 16, 2011 at 11:24 am

    Gabe, is there a Mac equivalent of the Unix eps2pdf command? Seems it might work well (as a Band-Aid, granted) to run that in any shell script after generating your EPSs.

    • 2. gabrielrossman  |  May 16, 2011 at 12:32 pm

      Yes. If you install a LaTex distro you have access to the usual Unix Ghostscript commands from the Terminal / scripts. My “graphexportpdf.ado” command relies on this functionality.

      Also, as Rense reminded us in the comments to the other post on this issue, it is similarly possible to do this in Windows.

  • 3. Eric Booth  |  June 16, 2011 at 11:51 am

    Do you know of a way in Stata for Mac to work in the GUI with -set graphics off- and still graph export to eps/png ? I tried:

    sysuse auto, clear
    set graphics off
    gr bar mpg price, name(g1, replace)
    gr export  "test.png", as(png) replace name(g1)

    without any luck. I’ve got a few do-files with thousands of graphs that take over-night to run, and I’d like to reduce the time it takes to run due to drawing the graph, not to mention the distraction of the graphs drawing on my screen.

    • 4. gabrielrossman  |  June 20, 2011 at 7:21 pm

      I think your problem is your syntax. I tried your script on my Mac (OS X 10.6, Stata MP 11.2) and it gives me this error message:

      no Graph window open

      However when I use this similar code it works in both the GUI “.app” and in Stata console.

      cd ~/Desktop
      sysuse auto, clear
      set graphics off
      graph box mpg, by(foreign)
      graph export mpgforeign.eps, replace
      set graphics on
      *have a nice day

      Try running my version and see what you get.

The Culture Geeks

%d bloggers like this: