Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dynamic documents with Stata and Markdown via Pandoc

    Thanks to Kit Baum the markstat command is available through SSC. This command combines Stata code and results with a narrative written using Markdown, producing by default a web page. If a LaTeX installation is available, markstat can produce a PDF file from exactly the same input script. It requires Stata 14, whereis from SSC, and Pandoc.

    The command works by separating the code from the narrative, runs the code through Stata, translates the narrative from Markdown to HTML or LaTeX using Pandoc, and then weaves the output files together. This avoid tedious cutting and pasting and promotes reproducible research.

    The markstat command puts a high premium on the simplicity of the input script, which emphasizes readability much in the spirit or Markdown itself. In the simplest syntax, Stata code is indented one tab or four spaces, as in the following example from the help file:

    Code:
    Stata Markdown
    --------------
    
    Let us read the fuel efficiency data that ships with Stata
    
        sysuse auto, clear
    
    To study how fuel efficiency depends on weight it is useful to
    transform the dependent variable from "miles per gallon" to
    "gallons per 100 miles"
    
        gen gphm = 100/mpg
    
    We then obtain a fairly linear relationship
    
        twoway scatter gphm weight || lfit gphm weight, ///
            ytitle(Gallons per 100 Miles) legend(off)
        graph export auto.png, width(500) replace
        
    ![Fuel Efficiency by Weight](auto.png)
    
    The regression equation estimated by OLS is
    
        regress gphm weight
    
    Thus, a car that weighs 1,000 pounds more than another requires on 
    average an extra 1.4 gallons to travel 100 miles.
    
    That´s all for now!
    The narrative may include equations. It may also include inline Stata or Mata code to quote results. There is an alternative strict syntax that uses code fences for Stata or Mata blocks, with an option to hide the commands and/or results. The command can also handle bibliographic citations, resolving them using a BibTeX database and listing them at the end of the document.

    The markstat command is described in an article in the current issue (17-3) of the Stata Journal, and is supported by a website at http://data.princeton.edu/stata/markdown, which includes installation instructions, documentation, examples, and a comparison with the new tools in Stata 15.

  • #2
    German, I just tried markstat and it worked great. Thank you! I am trying to figure out the limitations of the program, which may require LaTeX, and I have two related questions:

    1) Can we use markstat to create LaTeX Beamer presentations but using Markdown syntax? Here is an example of how the user-written program markdoc by Haghish does it:https://github.com/haghish/markdoc/b...amer/Beamer.do

    2) How would one add "continued on next page" message as sometimes is done in Stata Journal articles? I tried on a separate line the following code
    Code:
    \cnp
    but it just created a new page without the message.

    Comment


    • #3
      Hi Anders,

      1. A markstat update planned for later this fall will create HTML as well as LaTeX Beamer presentations, both using the same simple Stata/Markdown syntax. A lot is possible with Pandoc, just tinkering with making Stata graphs and tables look good.

      2. The stata.sty file defines \cnp as just \clearpage, which explains your result. But I see that Jeff Pitblado posted back in 2014 that they added a macro \onnextpage "just in case someome wanted this message back". I tried

      Code:
      This is page 1.
      
      \onnextpage
      
      And this is page 2.
      and got the message at the end of the page as you want it. And of course it is ignored when generating HTML.

      Comment


      • #4
        German, thank you! I confirm that \onnextpage works for me too; I am using Stata 15 on Windows 7.

        Comment

        Working...
        X