HTML files with asdocx
To create HTML files with asdocx, we need to change the file extension to .html
in the save() option. Since the save() option is sticky, we do not have to write it in the subsequent runs of asdocx. The HTML tables and text follow the same generic syntax of asdocx. You may explore the asdocx examples tab from the left menu to see how different types of tables can be created with asdocx. Similarly, if you want to add text / paragraphs to the HTML document, follow this link for knowing different options. As a matter of fact, all tables on this page and elsewhere on this website are created with asdocx.
In this post, I am going to create an HTML report that contains text and tables. I am also going to show how Stata and asdocx commands can be highlighted just like syntax highlighting feature in a text editor. Table and syntax formatting are controlled with a asdocx.css
file, that can be downloaded from here.
1. Base case: Table of summary statistics
Add asdocx as a prefix to Stata command and add .html
to the file name inside the save() option. Let’s create a file of basic summary statistics and create Report.html
file. Option replace
will replace any existing file with this name. If option replace
is not used, a new table is added to the given file if the file already exists.
* Load example data sysuse auto, clear asdocx sum, save(Report.html) replace
Variable | Obs | Mean | Std. Dev. | Min | Max |
---|---|---|---|---|---|
price | 74 | 6165.257 | 2949.496 | 3291 | 15906 |
mpg | 74 | 21.297 | 5.786 | 12 | 41 |
rep78 | 69 | 3.406 | 0.99 | 1 | 5 |
headroom | 74 | 2.993 | 0.846 | 1.5 | 5 |
trunk | 74 | 13.757 | 4.277 | 5 | 23 |
weight | 74 | 3019.459 | 777.194 | 1760 | 4840 |
length | 74 | 187.932 | 22.266 | 142 | 233 |
turn | 74 | 39.649 | 4.399 | 31 | 51 |
displacement | 74 | 197.297 | 91.837 | 79 | 425 |
gear_ratio | 74 | 3.015 | 0.456 | 2.19 | 3.89 |
foreign | 74 | 0.297 | 0.46 | 0 | 1 |