Applied Statistics Using Stata
Free Online Stata Tips & Tutorials. Data Management; Stata Graphs and Graphics; Data Analysis; Stata Programming; Advanced Statistics
Stata Weaver Package
| Quick Tips |
| Introduction |
| Weaving a document |
| Text |
| Graph |
| Examples |
Quick Tips
Weaver package provides a handful of commands for creating dynamic reports in Stata. Weaver was developed to meet the need of Lecturers and Statisticians that need to write and share a lot of reports, especially with other academic people which are not very interested in the details of the analysis and Stata codes. Weaver help to produce a clean HTML or PDF document that presents the important results and graphs, avoiding other technical and coding details that may not be of interst of other researchers with less background in statistics.
Introduction
Imagin you have worked on a data analysis and have written a long dofile. Let’s say that you wish to create a dynamic report that includes the important results and graphs and some text that explain the procedure and discuss the findings. Do you prepare a separate dofile for creating the document? This might not be a bad idea because in the process of analysis you may have tried several commands that you do not wish to include in your document. For example, maybe you just wanted to check for something that was not very necessary or perhaps, you wanted to check the distribution of your variables using several histograms but you think that it is better to just write a few lines in your document that the distribution of the variable seems reasonable and avoid puting them in your document. In these ocassions, it make sense to start another dofile which is intended to be used for generating a dynamic document. That would be the case if you were intending to share a SMCL logfile or translate a logfile to HTML, PDF, or Docx using Ketchup or MarkDoc.
Since Weaver is a very selective dynamic document producer, it can offer a better solution which is writing a document as you begin the analysis. By selective, I mean that when using Weaver, you have the option to include a particular code or output in the report or alternatively, include them in the dofile and execute them without including them in the report. In other word, Weaver runs in parralel to Stata and only writes the commands and output that you wish to include in the document. This feature gives Stata users a big advantage over other packages for developing dynamic report.
So how does Weaver provide the option to the user to select the codes that they wish to include in the document? Weaver creates a special logfile, which is a HTML logfile. The logfile is created by using the
In contrast to SMCL logfile which automatically registers everything which is written by the user, the HTML logfile requires an additional command to write the code, Stata outputs, or both in the report. In other words, Weaver even gives the option of only including a command or only including the results to the user which can help to produce cleaner reports for people who are not very interested in the codes or the statistical details.
Weaver includes a number of commands which all cooperate with one another to produce a decent HTML and PDF documents. The commands can be categorized in 4 groups. The first group includes commands that are related to creating the HTML logfile and the PDF documents. The second group of commands includes commands that are used for adding text and graphs to the document. The third group of commands includes the commands that provide the options about what commands and results to include in the document and what to exclude from the document. And finally, the fourth group is consist of commands that are used for refining the document. Below, these groups are explained and the commands relating to each group are named. In this article I introduce the Weaver commands and provide examples for each of them.
Weaving HTML and PDF documents
To begin a document, use the
â If you click on the
Perhaps it’s time to discuss a tiny limit casued by HTML (or any other web-based document). In contrast to other common document formats such as Docx, Doc, Odt, and PDF, HTML and other web-based documents do not appear in separate pages. Imagin browsing in a website and instead on scrolling down, you have to flip pages. Although such a feature can be programed for a website (i.e. the content appear in fixed sized pages) but probably many users will not find it very appealing.
However, HTML file can include codes that tell the regular printer or a PDF printer how to put the HTML codes into pages. For example, this website use specific CSS codes that makes it very printer friendly. In fact, by clicking on the printer icon (top-left side of this page) or pressing
â Therefore, although the HTML file shows the content to appear one after another, in the PDF document they may appear in separate pages. By default, the
The report command is the safety belt of the Weaver paclage. At allows you to print a PDF file from the current HTML logfile at anytime. By doing so, you can make sure that you are happy with the appearence of your document and everything is going as you wish. This command can save a lot of trouble if you use it while you’re developing the analysis and writing the report. To do so, simply type
The
Every experienced Stata users have figured out by now that the
ter name can be prince or wkhtmltopdf (for more information regarding these two printers see this article). Finally, you can also define the path to the printer with the
There is another command that may be useful for some of the advanced users or users that are familiar with web languages. The
In the example below, I write the following html code using the
Give the
I used the
â Remember that the
Text
There are two main ways for writing text in Weaver. The first one is using Markdown, which is the simple way and the second one is using the
However, in Weaver, if you write the text similar to Ketchup and MarkDoc, the text will not appear in the HTML logfile. Can you think of a reason why? If you have read the introduction of this article carefully you should probably remember the reason. Because Weaver needs to be told to include a command or results and by default ignores everything. To tell Weaver that you are about to start writing text in Markdown format, you should use the
Or alternatively, you can write:
So you may wonder that what these two commands actually do. The
The
If you wish to insert a separate HTML document instead, you can also use the
If you do not specify the html option,
â I fear that the
Graphs and images
Weaver offers several ways for inserting a graph or image to the document. The easiest and the best way is the
For example, imagin that I want to insert a graph named
Alternatively, you could import the same graph using the
I think I have a good reason to believe most of you would prefer the the
There is another possibility for importing a graph to the document which is using Markdown syntax. Although I have explained it in details in the Using Markdown with Stata article, I brifly explain the Markdown syntax for importing a graph below:
The description is optional and prints the description under the graph. if you do not wish to describe the graph leave the brackets empty i.e.
Download example templates
Download the following do-files templates to see examples of how to use the Ketchup package properly. Right click and select “Save Link As” to download the files. These example templates show you how to write text with Markdown, how to insert a graph using Markdown, HTML, and img command.