Germán Rodríguez
Stata Markdown Princeton University

Pandoc Tables

There are two main ways to produce tables in Pandoc's version of Markdown, using a simple syntax and pipe tables. I prefer the latter because it can easily be combined with inline code.

Here is how to generate a table showing average gallons per 100 miles for foreign and domestic cars before and after adjustment for weight. We use a strict code block to te able to hide the commands and quietly to supress output, and then display the stored results in a pipe table.This is the input:

tables.stmd
A Dynamic Table
---------------

```s/
    quietly sysuse auto, clear
    quietly gen gphm = 100/mpg
    quietly regress gphm foreign
    mat b = e(b)
    quietly sum weight
    scalar mw = r(mean)
    quietly reg gphm weight foreign
    scalar dom = _b[_cons] + _b[weight] * mw
    local f %6,2f
```

The table below shows average fuel efficiency in gallons per 100 miles for foreign 
and domestic cars before and after adjustment for weight:

| Car Type   | Unadjusted            | Adjusted                  |
|:-----------|----------------------:|--------------------------:|
| Foreign    | `s `f' b[1,1]+b[1,2]` | `s `f' dom + _b[foreign]` |
| Domestic   | `s `f' b[1,2]`        | `s `f' dom`               |

Foreign cars use less fuel than domestic cars but are also lighter,
when we compare cars with the same weight the imports use 
six-tenths of a gallon more per 100 miles than the domestic cars.

And this is how this is rendered by the command markdown using tables, strict. Don't forget to specify the strict option.

tables.html

A Dynamic Table

The table below shows average fuel efficiency in gallons per 100 miles for foreign and domestic cars before and after adjustment for weight:

Car Type Unadjusted Adjusted
Foreign 4,31 5,46
Domestic 5,32 4,83

Foreign cars use less fuel than domestic cars but are also lighter, when we compare cars with the same weight the imports use six-tenths of a gallon more per 100 miles than the domestic cars.

 

If you have installed markstat, whereis and pandoc, you can reproduce this example by typing

copy http://data.princeton.edu/stata/markdown/tables.stmd tables.stmd
markstat using tables, strict

You need to download the Stata Markdown script first because markstat works with local files.