John Muschelli pointed me to this Stata program:
https://github.com/amarder/stata-tutorial/blob/master/knitr.do
It parses a .domd
file which contains markdown and Stata code and produces a .md
file with executed Stata code. The name of the file to be parsed is at the end of the knitr.do
file.
More specifcally:
Download the
knitr.do
file from https://github.com/amarder/stata-tutorial/blob/master/knitr.doDownload the
clustered-standard-errors.domd
file from https://github.com/amarder/stata-tutorial/blob/master/clustered-standard-errors.domdSave them both in some directory.
Modify the last line of
knitr.do
to reflect the complete path of its directory (e.g. D:\Desktop\knit_example\clustered-standard-errors.domdRun
knitr.do
to get your markdown (.md
) file (and an intermediate.md1
file).
Note that knitr.do
contains the programs that do the work and a line (the last one):
knit "whatever-file.domd"
that calls the program.
So you basically write a .domd
file [that of step (2) is only an example] containing Markdown syntax and Stata commands, run knitr.do
adjusting the file name, and get a Markdown file with executed Stata commands.
There are several caveats:
- Only one-liner Stata commands are allowed. A loop, for example, won't work.
- ".domd" can't be part of the file name.
- If there is an error with a Stata command, the user gets no return code.
- File handles need to be manually closed if user hits the Break button when the program is running or if there is a Stata command error.