When you write a document in the standard dynamic Markdown format, it is processed in two stages. First the Stata code blocks and in-line references are processed, and the results are substituted into your document. Then the Markdown elements of your document are processed, producing a final HTML document.
The standard approach to including dynamic content in a Markdown document is to place some code-to-be-processed in a fenced code block (demarcated with three or more backticks or tildes). This fenced code block has an additional information tag, the first word of which is reserved for the name of the programming language to be invoked.
This usually looks like
~~~stata
-- code --
~~~
Similarly, dynamic in-line code (demarcated with single backticks) has an additional info tag for the programming language. It typically looks like
some text `stata --code--` more text
In Stata Markdown, the in-line code is limited to display commands (not arbitrary Stata commands).
The stmd
command only processes code in Stata (this could change in the future, to include Mata or other languages). The language for each code block may be specified in a number of alternative ways.
That is, you may use the keyword "stata" or the keyword "s", with or without curly braces. The first option, the simple keyword "stata", gives you HTML with a class="language-stata"
declaration, useful if your documents make use of style sheets. The "{stata}" with braces, is compatible with knitr
documents in R. The last two options, "{s}" and "s" are compatible with markstat
documents.
Markdown | Resulting Document |
---|---|
Using "{stata}"
|
|
Using "{s}"
|
|
Using "stata" (no braces)
|
|
Using "s" (no braces)
|
|
In-line dynamic code begins with a backtick followed by a language keyword, followed by a space, followed by a Stata display
directive (a display
command without the keyword “display”).
Markdown | Resulting Document |
---|---|
Using "{stata}" in-line
|
Mean price: 6165.3 |
Using "{s}" in-line
|
Standard deviation of price: 2949.5 |
Using "stata" (no braces)
|
Minimum price: 3291.0 |
Using "s" (no braces)
|
Maximum price: 15906.0 |