2 putpdf intro — Introduction to generating PDF files
Introduction
putpdf is a suite of commands used to write paragraphs, images, and tables to a PDF file. This
allows you to create PDF files that include Stata results and graphs. With putpdf, you can also format
the text, tables, and images in the document you create.
To get started with the putpdf commands, it is best to see them in action. Here we demonstrate
how to create a PDF file, include text, add a graph, and incorporate an estimation table all from within
Stata.
This example shows the basic tools you need to create your own document. However, this is only a
starting point. You may want to create more extensive and more customized documents, and putpdf
allows you to do that. We save the details of customizing text, tables, and images for the individual
entries of the commands listed above.
Create a PDF file
To demonstrate, we create a report on 1978 automobiles using auto.dta.
. use https://www.stata-press.com/data/r18/auto
(1978 automobile data)
Before we can add any content to the report, we first need to create an active .pdf document in
memory. We do this with the putpdf begin command.
. putpdf begin
Because we did not include any options with putpdf begin, the document created uses the
letter page size and the portrait orientation.
Add a paragraph with text
Now that the document is created, we can add other objects such as paragraphs, images, and tables
to it. We begin by adding a title to our report using the Courier font with size 20 and centering it.
. putpdf paragraph, font("Courier",20) halign(center)
. putpdf text ("Report on 1978 automobiles")
We added strings to this paragraph, but text can include any valid Stata expression. Below, we add
text with summary statistics for our data by referring directly to the results stored after summarize.
We type return list and see that r(N), r(mean), and r(max) store the number of automobiles,
the average MPG, and the maximum MPG among those automobiles.
. summarize mpg
Variable Obs Mean Std. dev. Min Max
mpg 74 21.2973 5.785503 12 41
. return list
scalars:
r(N) = 74
r(sum_w) = 74
r(mean) = 21.2972972972973
r(Var) = 33.47204738985561
r(sd) = 5.785503209735141
r(min) = 12
r(max) = 41
r(sum) = 1576