Written and maintained by CASRAI Editorial Board
Published
On this page
Stata draws graphs with the graph command family: graph twoway, graph bar, graph box, graph dot, graph pie and graph matrix draw them, graph save and graph export write them to disk, and graph combine arranges several into one figure. The StataCorp Stata 19 Graphics Reference Manual describes the family under the entry [G-2] graph, which states simply that “graph draws graphs”. This guide maps the whole family, then walks through one reproducible do-file workflow: draw two graphs, name them, combine them, and export the result for a manuscript.
What Stata graphics are used for in research
Researchers use Stata graphics to inspect data before modelling, to show distributions and relationships in papers, and to produce figures from a do-file so that a figure can be regenerated when the data change. The manual points out one reason to prefer commands over menus: “The advantage of graph export is that you can include it in do-files.” A figure produced by a script is documented and repeatable; a figure saved by hand from a window is not.
The page you are reading covers the cross-cutting commands. For a single chart type, see the dedicated CASRAI guides on histograms in Stata, bar charts in Stata, box plots in Stata and scatterplots with twoway scatter and lfit. For colour choices see colors in Stata.
The Stata graph command family
The table below is a map of the commands that [G-2] graph groups together. Each row names what the command does in the manual’s own terms.
| Task | Commands | What they do |
|---|---|---|
| Draw | graph twoway, graph matrix, graph bar, graph dot, graph box, graph pie |
Scatterplots and line plots (twoway), scatterplot matrices, bar charts, dot charts, box-and-whisker plots, pie charts |
| Save and redisplay | graph save, graph use, graph display, graph replay |
Save a graph to disk, redisplay a graph stored on disk, redisplay a graph held in memory |
| Combine | graph combine |
Combine multiple graphs into one |
| Print and export | graph print, set printcolor, graph export |
Print a graph, set print colour, export a graph to formats such as PostScript, PDF or PNG |
| Manage graphs in memory | graph dir, graph describe, graph rename, graph copy, graph drop, graph close |
List graph names, describe, rename, copy and remove graphs |
| Schemes and defaults | graph query, query graphics, set scheme, graph set, set graphics |
List available schemes and styles, identify or set the default scheme, set printing and export options, control whether graphs are displayed |
The graph twoway family is the largest of these; its plot types (scatter, line and others) are documented in their own manual entries.
Install or access
Stata is commercial software from StataCorp. Obtain it, and its documentation, only from the vendor at stata.com; the Stata 19 manuals, including the PDFs cited below, are published at stata.com/manuals. Many universities provide licences to staff and students, and the CASRAI page Stata licence explains the licence types. Format availability for exported graphs depends on the Stata flavour and operating system, as the export table below shows.
Step by step: draw, name, combine and export two graphs
The manual’s own worked example uses the Stata Press dataset uslifeexp (US life expectancy, 1900-1999), which can be loaded from https://www.stata-press.com/data/r19/uslifeexp. The steps below follow that example.
- Load the data.
use https://www.stata-press.com/data/r19/uslifeexp, clear - Draw each graph and give it a name held in memory.
line le_male year, name(male)thenline le_female year, name(female). Naming graphs withname()keeps them in memory so they can be combined and exported by name. - Combine them.
graph combine male female(the manual abbreviates the command asgr combine). By default graphs are arranged row-first in a grid; shrinking of text and markers increases as more graphs are combined. - Improve the layout. The manual’s better version for two graphs is
gr combine male female, col(1) iscale(1):col(1)stacks them in one column andiscale(1)prevents the fonts from shrinking. - Align the axes. The two y axes in the example start at different values (a minimum of 40 for one and about 37 for the other), which makes the panels hard to compare. Add
ycommonso both use the same scale. - Export for a manuscript.
graph export mygraph.png, width(600) height(450) replace. Withoutname(), Stata exports the topmost graph; the combined graph is namedGraphby default.
If the graphs were saved to disk instead of held in memory (for example with line le_male year, saving(male)), refer to them with the .gph suffix or in quotes: gr combine male.gph female.gph.
Useful graph combine options
These options are listed in the [G-2] graph combine entry. The command is also reachable from the menu: Graphics > Table of graphs.
| Option | Effect |
|---|---|
rows(#) or cols(#) |
Set the number of rows or columns in the arrangement |
colfirst |
Fill the arrangement column-first instead of row-first |
holes(numlist) |
Leave specified cells empty, for example graph combine g1 g2 g3, holes(2) |
iscale(#) |
Control how much text and markers are shrunk; the manual recommends values from 0 to 1 |
ycommon, xcommon |
Give all graphs the same y or x scale |
commonscheme and scheme(schemename) |
Apply one scheme to all combined graphs, for example graph combine g1 g2, scheme(sj) commonscheme |
nodraw |
Create the combined graph without displaying it |
name(name, replace) |
Name the result; the default is name(Graph, replace) |
saving(filename, asis replace) |
Save the combined graph to disk as it is created |
Save versus export
graph save and graph export do different jobs. graph save writes a graph only in Stata’s own .gph format; the manual says to use graph export to produce other formats such as .png or .pdf.
- Syntax:
graph save [graphname] filename [, asis replace]. If you give no extension,.gphis assumed. - Live format (default): the saved graph can be edited in later Stata sessions, and its look is controlled by the scheme.
asis: freezes the graph so it cannot be edited or have its scheme changed. As-is files usually require fewer bytes and display more quickly. The manual says the choice makes no difference for printing.- At draw time: the
saving(filename[, asis replace])option on a graph command saves while drawing.
Use graph save when you want to reopen and edit the graph in Stata later; use graph export for the file you will submit or insert in a document.
Output and how to read it
The syntax is graph export newfilename.suffix [, options]. When you omit as(), Stata chooses the format from the file suffix. The data table below lists the nine suffixes the manual names and the platform restrictions it states. The options are name(windowname), as(fileformat), replace and the override options; width() and height() set the size of raster output, as in the manual’s example graph export mygraph.png, width(600) height(450).
Other examples from the manual: graph export mygraph.pdf; graph export mygraph, as(pdf); graph export mygraph.eps, name(MyGraph) replace. A suffix not in the list requires as().
Reading a combined figure: check that panels compare like with like. Without ycommon or xcommon each panel scales its own axis, so identical-looking lines can hide different ranges. These options have no effect on the categorical axes of bar, box and dot graphs.
To export a graph that is stored on disk, run graph use gph_filename and then graph export output_filename.suffix; for a graph in memory, run graph display name and then graph export. In both routes do not use nodraw, because the graph must be displayed to be exported.
Troubleshooting
| Problem | Cause and fix (per the Stata 19 manual) |
|---|---|
Error that graphs “could not be found” after graph combine |
Disk graphs need the .gph suffix or quotes (“male”). Without them Stata assumes memory graphs. |
| The wrong graph is exported | Without name(), graph export exports the topmost graph. Stata for Unix (GUI) users should always use name(). |
| Text and markers look tiny after combining | The default iscale shrinks more as the number of graphs grows. Set iscale(1) or another value between 0 and 1. |
| Combined panels are hard to compare | Add ycommon and/or xcommon. They do nothing on categorical axes of bar, box and dot graphs, and when twoway graphs are combined with bar, box or dot graphs they affect only graphs of the same type as the first graph combined. |
| Export from a stored graph fails or shows nothing | Do not use nodraw with graph use or graph display before graph export. |
| Chosen format is unavailable | tif is not available for Stata(console), emf is available only for Stata for Windows, and gif only for Stata for Mac. |
If you save a graph to a script-friendly format, you can also export from a Graph window by right-clicking and choosing Save Graph, or via File > Save Graph; the manual lists these as equivalent to the command.
Free alternatives
Stata is licensed software. If you do not have a licence, the same kinds of charts can be built in other environments. CASRAI covers the R equivalent for scatterplots in scatterplots in R. Reproducible-figure habits described here, such as scripting every figure and exporting from code, apply in any tool.
Frequently asked questions
How do I save a Stata graph as a PNG or PDF?
Use graph export with the target suffix, for example graph export mygraph.png or graph export mygraph.pdf. graph save writes only Stata’s .gph format.
How do I put two Stata graphs side by side?
Draw each with a name(), then run graph combine name1 name2. Add cols(2) or rows(2) to control the arrangement.
What is the difference between graph save and graph export?
graph save keeps an editable .gph file for later Stata sessions; graph export creates files in other formats for use outside Stata.
Which file formats can graph export write?
ps, eps, svg, emf, pdf, png, tif, gif and jpg by suffix; see the data table below for platform restrictions.
Can I include graph commands in a do-file?
Yes. The manual notes that the advantage of graph export is that it can be included in do-files; see also Stata code.
Sources
All commands and behaviours above come from the StataCorp Stata 19 Graphics Reference Manual (read 2026-11-14).
Data: Stata graph export file suffixes and platform restrictions
File suffixes that graph export recognises without as(), with the format and the platform restrictions stated in the Stata 19 manual entry [G-2] graph export.
| Suffix | Format | Platform restriction |
|---|---|---|
| ps | PostScript | none stated |
| eps | Encapsulated PostScript | none stated |
| svg | SVG | none stated |
| emf | Enhanced Metafile | Stata for Windows only |
| none stated | ||
| png | PNG | none stated |
| tif | TIFF | Not available for Stata(console) |
| gif | GIF | Stata for Mac only |
| jpg | JPEG | none stated |
Sources
- [G-2] graph export, Stata 19 Graphics Reference Manual (accessed 2026-11-14)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







