Create Word documents from Stata
Create webpages from Stata
Intermix text, regressions, results, graphs, etc.
Intermix the full output of Stata commands
Intermix individual values from the results of Stata commands
Create tables in Word or HTML from the results of Stata commands
Changes in data or commands are automatically reflected in the document or webpage
Have you ever wanted to create Word, PDF, or HTML files that report on what you have done? Stata provides commands for doing that:
Command | Purpose |
---|---|
dyndoc | Create Word documents or HTML from Markdown |
putdocx | Create Word documents |
putpdf | Create PDF files |
Here we tell you aboutdyndoc.
You first create a file containing text to be formatted using the Markdown text-formatting language intermixed with Stata commands that produce the output you want in your final document. Markdown is a simple, standardized text-formatting language that you can read about atWikipedia. You mix Markdown with Stata commands that create the output you want. Think of the file you create as being a do-file on steroids.
You then rundyndoc to produce a Word document (.docx) or webpage—an HTML file. The resulting file will contain formatted text along with the Stata output and graphs that your commands produced.
The examples below on this webpage were created using that approach!
They are calleddynamic documents, which means that if the data ever change, we can run the original source document back throughdyndoc to create an updated webpage.
Creating adyndoc file is as easy as creating a do-file. Here's one that creates an HTML file with only Stata output:
example1.txt |
The four tildes in a row,~~~~, are Markdown syntax to start and end a code block.
Terms in<< …>> are called Stata dynamic-document tags. The code block is bounded by<<dd_do >> …<</dd_do>>. Stata code inside<<dd_do>> …<</dd_do>> is executed and its output substituted into the HTML document. We merely save the file above asexample1.txt, typedyndoc example1.txt in Stata, andexample1.html is created for us:
. webuse auto, clear(1978 automobile data). summarize price Variable | Obs Mean Std. dev. Min Max-------------+--------------------------------------------------------- price | 74 6165.257 2949.496 3291 15906
Let's add some text around our example:
example2.txt |
You can imagine what this document would look like. Here is a better version of it:
example3.txt |
To create the dynamic document fromexample3.txt, in Stata, we type
.dyndoc example3.txt (output omitted)
The new fileexample3.html will be created. And the result looks like this:
We will use the auto dataset. It includes variable price:
. webuse auto, clear(1978 automobile data). summarize price Variable | Obs Mean Std. dev. Min Max-------------+--------------------------------------------------------- price | 74 6165.257 2949.496 3291 15906
The mean of price is 6165.257. We will also …
Finally, we can even add a Stata graph as an SVG file and someregression output as an HTML table to our document:
We convert the dynamic document inexample4.txt to HTML by typing
.dyndoc example4.txt (output omitted)
and the result inexample4.html is
This really is a dynamic document. If the data ever change, all we have to do is rerundyndoc example4.txt to update the page.
dyndoc can substitute output, substitute results in-line, substitute graphs, and create tables from the results of some Stata commands. All of this can be saved as a Word document or an HTML file.
Read more about converting dynamic Markdown documents to Word or HTML in theStata Reporting Reference Manual; see[RPT] dyndoc.
Learn more about Stata'sreporting features.
Learn
Free webinars
NetCourses
Classroom and web training
Organizational training
Video tutorials
Third-party courses
Web resources
Teaching with Stata
© Copyright 1996–2025 StataCorp LLC. All rights reserved.
×
We use cookies to ensure that we give you the best experience on our website—to enhance site navigation, to analyze usage, and to assist in our marketing efforts. By continuing to use our site, you consent to the storing of cookies on your device and agree to delivery of content, including web fonts and JavaScript, from third party web services.
Cookie Settings
Last updated: 16 November 2022
StataCorp LLC (StataCorp) strives to provide our users with exceptional products and services. To do so, we must collect personal information from you. This information is necessary to conduct business with our existing and potential customers. We collect and use this information only where we may legally do so. This policy explains what personal information we collect, how we use it, and what rights you have to that information.
These cookies are essential for our website to function and do not store any personally identifiable information. These cookies cannot be disabled.
This website uses cookies to provide you with a better user experience. A cookie is a small piece of data our website stores on a site visitor's hard drive and accesses each time you visit so we can improve your access to our site, better understand how you use our site, and serve you content that may be of interest to you. For instance, we store a cookie when you log in to our shopping cart so that we can maintain your shopping cart should you not complete checkout. These cookies do not directly store your personal information, but they do support the ability to uniquely identify your internet browser and device.
Please note: Clearing your browser cookies at any time will undo preferences saved here. The option selected here will apply only to the device you are currently using.