Announcement

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

  • Dynamic Presentations with Stata and Markdown

    Thanks to Kit Baum, markstat 2.0 is now available from SSC. To update type ssc install markstat, replace.

    The big news in this release is support for slide shows. You write your presentation using Stata and Markdown, and markstat leverages Pandoc to generate HTML slides using the S5 engine or PDF slides via LaTeX using Beamer. Below is a short script including metadata and two slides, an excerpt from a short presentation called deck.stmd that you can see in full in my website here.

    Code:
    % Dynamic Presentations with Stata and Markdown
    % Germán Rodríguez
    % `s c(current_date)`
    
    # Stata Results {.fragile}
    
    Here's the proverbial fuel efficiency dataset:
    
        sysuse auto, clear
        gen gphm = 100/mpg
        quietly reg gphm weight
        _coef_table
    
    So a car that weights 1,000 pounds more than another will need on average
    `s %5.1f 1000*_b[weight]` more gallons to travel 100 miles.
        
    # A Stata Graph {.fragile}
    
    Using gallons per 100 miles leads to a more linear relationship
    
        twoway scatter gphm weight || lfit gphm weight ///
            , ytitle(Gallons per Mile) legend(off)
        quietly graph export short.png, width(500) replace
    
    ![Fuel Efficiency by Weight](short.png){width="60%"}
    The command markstat using deck, slides generates an HTML slide show using the S5 engine. Changing the option to slides(santiago) uses the Santiago theme. The graph slide is shown below and the complete show is here.

    Click image for larger version

Name:	santiago3.png
Views:	1
Size:	17.5 KB
ID:	1418600

    If you have a LaTeX installation, the command markstat using deck, beamer generates PDF slides via LaTeX with Beamer, and the option beamer(madrid) uses the Madrid theme shown here, just one of many themes available. The {.fragile} attribute is there to keep Beamer happy with verbatim content like Stata output.

    The new nodo option lets you tinker with the narrative or change engines and/or themes without re-running the Stata analysis, an idea from Ben Jann’s nodo option of texdoc.

    As usual, much more at my website, including help getting started, documentation, and many examples, including the complete deck.stmd script, and a two-column example showing slides with side-by-side code and graphs.

    Feedback is always appreciated.

  • #2
    If you have a previous version of `markstat`, then

    adoupdate markstat

    is also a good way to update.
    Doug Hemken
    SSCC, Univ. of Wisc.-Madison

    Comment


    • #3
      Instead of -markstat- (well, actually pandoc internally called by markstat) including the CSS code into the HTML file, is it possible to include just a link to the CSS file?

      The thing is, I want to produce a number of HTML files with markstat pointing to the same CSS stylesheet, so that if I want to make cosmetic changes to the HTML files, I can do it by modifying only 1 file once (the CSS stylesheet).

      Comment


      • #4
        Off the cuff, I think I remember a "css" field for the YAML header. I imagine any header that is pandoc-valid gets passed through?
        Doug Hemken
        SSCC, Univ. of Wisc.-Madison

        Comment


        • #5
          Hi Andrea. It depends on whether you are generating a document or slides, as the templates are different. It sounds to me like you are interested in documents, not slides. In general you can use a "header-includes" in the YAML metadata. For example if I want to use the Bootstrap framework I may code

          Code:
          ---
          header-includes:
           - <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css"/>
           - <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
           - <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
          ---
          For documents markstat then injects its own markstat.css which is pretty harmless, but you can avoid this by including a custom markstat.css file in your working directory. This can be empty, but I recommend you define at least pre.stata somewhere.

          For slides things are different, since you need a lot of CSS and JavaScript for the presentation. In this case markstat gets the files from a system directory or the current working directory. So you could make a copy of the S5 folder and customize it at will.

          Comment


          • #6
            Dear German, thank you very much for your kind and swift reply.
            I'd like to take this opportunity to thank you for the -markstat- command and, more in general, for your website, which contains tons of excellent and extremely useful material!

            Comment


            • #7
              Thanks for the kind words, Andrea. Glad to hear you find the material useful.

              Comment


              • #8
                Thank you to this wonderful markstat command I already tested.

                What I am discovering now is the use of marstat to produce Beamer slides. It works perfectly even with my very basic knowledge of Markdown.

                Does someone know how to modify the code in order that the slides produced appears with a navigation bullets bar or sections inside the pdf in order to move easilly if needed ? (in LaTeX you can have a navigation bar at the top of the slides, with a bullet per section or subsection, indicating where you are inside the presentation, that allows you to click someore and go there.)

                Maybe to do that, I have to modify the .css files ? Every idea is welcome!

                and thank you again for this very helpful command German!

                Comment

                Working...
                X