Saving & exporting graphs

  • The best way to save a graph (of any type) is to use the command graph export
  • You can either export the last graph in memory or simply indicate the name of the graph (provided you named it before)
  • Check help graph export to see the available data formats.

Some hints:

  • If you want to combine two or more graphs with the same legend, use the user-written command grc1leg to only display the legend once in the combined graph (ssc install grc1leg before you use it for the first time).
  • If you want to combine two or more graphs which should have different sizes, use the options fxsize() and fysize() when constructing the single graphs. They specify how many percent of the available height (fysize) respectively width (fxsize) should be occupied by the single graph. Your single graphs will look strange, but the combined graph will look nice. You find an example in the help-file for "graph combine" (>>Remarks>>Controlling the aspect ratio of subgraphs)

* Saving graphs in Stata format

// Graphs can be saved in Stata format with the commed graph save
twoway scatter price weight
graph save graph1, replace

// Alternatively, save graphs in Stata format with the option saving()
twoway scatter price weight, saving(graph2, replace)

// These file can only be opened with Stata


**************************************
* Exporting graphs
sysuse auto, clear

// Graphs can be exported to other formats using the command graph export

// Create a graph for export, assigning a name
hist price, name(test_export, replace)

// Raster format
graph export "price_hist.png", name(test_export) replace 
// PDF format
graph export "price_hist.pdf", name(test_export) replace 
// Vector format 
graph export "price_hist.eps", name(test_export) replace 
// option name() refers to the Graph window to be exported