Germán Rodríguez
Stata Markdown Princeton University

Ian Watson's `tabout` can produce beautiful frequency tables and tables of summary statistics, with output in LaTeX or HTML, and as noted in Chapter 9 of the User's Guide for version 3, it can also produce dynamic documents.

Here we show how you can combine the power of `tabout` with the simplicity of `markstat` to produce dynamic documents, using an abbreviated version of the example on page 72 and table 34 of the User's Guide.

Note that we use `tabout` to generate `table34.html` and then simply `.include table34.html` in the document. We omit the options `topf`, `topstr`, `botf` and `botstr`, using simple Markdown with inline code instead. Here is the script

`tabout.stmd`
``````s/
quietly sysuse auto, clear
quietly sum weight
local meanwt = r(mean)
quietly sum length
local meanlen = r(mean)
local obs = r(N)
quietly tabout rep78 foreign using table34.html, replace ///
style(htm) font(italic) c(mean weight) f(0c) sum ///
twidth(9) h1(Car type (mean weight in lbs.)) h3(nil) ///
title(Table 34: Short report example) fn(auto.dta)
```

The title of my short report
----------------------------

This is an excerpt of the report to focus on the dynamic parts.
And now we have an important result: __`s %3.2f `meanwt'`__ is
the average weight of all vehicles. And a second important
result: __`s %3.2f `meanlen'`__ is the average length.

And now we have the first table.

<center>

.include table34.html

</center>
```

And this is how the script is rendered by the command `markstat using tabout, strict`. Don't forget to specify the `strict` option.

`tabout.html`

## The title of my short report

This is an excerpt of the report to focus on the dynamic parts. And now we have an important result: 3019.46 is the average weight of all vehicles. And a second important result: 187.93 is the average length.

And now we have the first table.

Table 34: Short report example

 Car type (mean weight in lbs.) Domestic Foreign Total 1 3,100 3,100 2 3,354 3,354 3 3,442 2,010 3,299 4 3,532 2,208 2,870 5 1,960 2,403 2,323 Total 3,368 2,263 3,032

auto.dta

Note. `tabout` generates the table title and footer as separate paragraphs rather than a `caption` and `tfoot`. As a result they are not centered when the table is centered. To keep everything together I wrapped the table in center tags.

To obtain LaTeX output you just need to change the output to `using table34.tex`, the style to `style(tex)`, and then use `\input{table34.tex}` instead of `.include`.

In order to convert the generated LaTeX to PDF, however, we need to add four packages used by `tabout` which are not included in the Pandoc template. Fortunately this is easy to do with "header includes". This example uses only the first three packages but I include all four for completeness. At the start of the script simply insert this YAML block:

```---