slidegraph

Automated stepped and layered graphs for presentation slides in Stata

View the Project on GitHub aarondwolf/slidegraph

slidegraph

Automate stepped, layered figures for slide presentations (such as LaTeX Beamer or PowerPoint builds) in Stata using opacity modulation.


Installation

From SSC (Boston College Archive)

The official release of slidegraph can be installed directly from the SSC archive:

ssc install slidegraph

To update an existing installation:

ssc install slidegraph, replace

From GitHub (Optional for Latest Updates)

To install the latest development version with recent updates directly from GitHub:

net install slidegraph, from("https://aarondwolf.github.io/slidegraph") replace

Or from a local cloned directory:

net install slidegraph, from("C:/path/to/slidegraph") replace

The Core Concept

When presenting empirical results or model progressions in slide decks, speakers frequently build complex graphs layer by layer:

  1. Show baseline data points.
  2. Introduce comparison groups.
  3. Overlay fitted trendlines or counterfactual predictions.

In standard Stata workflows, plotting subsets of series across different graphs leads to distracting visual jitter:

The slidegraph Solution

Instead of conditionally omitting series, slidegraph plots all series in every single frame and modulates their visibility across sequential frames by appending Stata opacity modifiers:

Because all series are evaluated in every frame, Stata locks in fixed axis limits, consistent tick intervals, and an identical legend bounding box throughout the entire animation sequence.

[!TIP] Stationary Legends: Because all series are plotted in every frame, legend keys remain in fixed positions across slides rather than expanding or jumping as layers appear.

Design Philosophy: Why Color-Based Substitution?

Stata’s graphing ecosystem spans a wide variety of built-in commands (twoway, graph bar, graph box, graph dot, histogram) and community-contributed packages (coefplot, marginsplot, binscatter, etc.), each with its own syntax for defining series and plot elements. Attempting to parse plot structures directly would either restrict slidegraph to basic twoway commands or make it fragile when used with wrapper packages.

Despite their syntactic differences, nearly all Stata graph commands share a common denominator: they accept standard Stata color specifications. By keying frame visibility to color tokens rather than plot syntax, slidegraph remains completely command-agnostic—any element whose color you can specify can be sequenced across slides.

Limitation & Workarounds: Multiple Layers with the Same Color

Because slidegraph identifies layers by their color token, two plot elements that use the exact same color string cannot be toggled independently:

// Both scatter plots will turn on/off together if both use 'navy'
twoway (scatter y1 x1, mcolor(navy)) (scatter y2 x2, mcolor(navy))

If you need two series to appear in the same visual color on different frames, you have two simple workarounds:

  1. Use visually identical color aliases: Stata treats unit intensity multipliers and equivalent RGB triplets as identical on screen, while slidegraph sees them as distinct tokens:
    • Layer 1: mcolor(navy)
    • Layer 2: mcolor(navy*1) (or mcolor(navy*1.0))
    • Layer 3: mcolor("26 71 111") (the RGB equivalent of navy)
      slidegraph set, colors(navy navy*1 "26 71 111") cumulative
      
  2. Copy and tweak the generated commands: slidegraph prints the exact expanded command for every frame to the Stata Results window. In complex cases, you can assign temporary distinct colors to generate the sequence, then copy the echoed commands from the Results window and adjust the colors manually.

Architecture & Subcommands

1. slidegraph set

Configures the visibility sequence across frames and validates the pattern matrix.

// Explicit custom patterns:
slidegraph set, patterns(color1 pat1 color2 pat2 ...) [off(integer 0)] [dim(integer 20)]

// Shorthand presets (no manual binary strings required):
slidegraph set, colors(color1 color2 ...) cumulative|spotlight [off(integer 0)] [dim(integer 20)]

2. slidegraph

Executes the stored multi-frame sequence. Users provide standard graph commands after the colon (:) with all native graph options.

slidegraph [, stub(name) saving(filename) full] : <graph command>

3. slidegraph export (Aliases: slidegraph tex, slidegraph beamer)

Generates a clean LaTeX Beamer overlay .tex file that can be immediately \input into a Beamer slide.

slidegraph export [using filename.tex] [, path(string) saving(filename) options(string) replace]

4. slidegraph query (Aliases: list, describe, or slidegraph alone)

Displays the active configuration in the Stata Results window, including frame count ($N$), color-pattern pairs, dim/off modifiers, RGB status, and last saving() path. Calling slidegraph with no arguments when a configuration is active runs query automatically.

slidegraph query

5. slidegraph clear (Alias: reset)

Clears all stored configuration macros ($SG_*) from global memory. Recommended between distinct figure definitions in do-files to prevent state spillover.

slidegraph clear

Quickstart & Demonstrations

Run the included demonstration script examples/slidegraph_demo.do (or see the complete LaTeX Beamer example in examples/beamer/):

1. Progressive Build with Shorthand cumulative Preset

sysuse auto, clear

// Shorthand setup: 2 frames (Domestic only -> Domestic + Foreign)
slidegraph set, colors(navy cranberry) cumulative

// All twoway options are placed after the colon
slidegraph : twoway ///
    (scatter price mpg if foreign==0, mcolor(navy))         ///
    (scatter price mpg if foreign==1, mcolor(cranberry)),   ///
    title("Price vs MPG by Foreign Status")

2. 3-State Narrative Spotlight Build (spotlight with dimming)

// Spotlight: Series under discussion is 100% opacity; previously introduced series are dimmed to %25
slidegraph set, colors(navy cranberry midblue) spotlight dim(25)

slidegraph, stub(spot) : twoway ///
    (scatter price mpg if foreign==0, mcolor(navy))         ///
    (scatter price mpg if foreign==1, mcolor(cranberry))     ///
    (lfit price mpg, lcolor(midblue)),                      ///
    title("Price vs MPG: Spotlight Sequence")

3. Full Paper Figure + Slide Sequence + LaTeX Beamer Export

slidegraph set, colors(navy cranberry midblue) cumulative

// full option outputs paper_slide.pdf (paper figure) AND paper_slide_1..3.pdf (slide frames)
slidegraph, stub(paper_slide) saving(paper_slide.pdf) full : twoway ///
    (scatter price mpg if foreign==0, mcolor(navy))                 ///
    (scatter price mpg if foreign==1, mcolor(cranberry))           ///
    (lfit price mpg, lcolor(midblue)),                             ///
    title("Price vs MPG with Overall Trend")

// Export LaTeX overlay code pointing to presentation figures directory
slidegraph export using "paper_slide_overlays.tex", path("figures/slides") replace

In your LaTeX Beamer presentation, simply insert:

\begin{frame}{Model Progression}
  \centering
  \input{paper_slide_overlays.tex}
\end{frame}

Or present talking points side-by-side with synchronized builds (see full compilable demo in examples/beamer/):

\begin{frame}{Model Progression}
  \begin{columns}[T]
    \begin{column}{0.42\textwidth}
      \begin{itemize}
        \item<1-> \textbf{Frame 1}: Baseline data points
        \item<2-> \textbf{Frame 2}: Reveal comparison group
        \item<3-> \textbf{Frame 3}: Overlay fitted trendline
      \end{itemize}
    \end{column}
    \begin{column}{0.58\textwidth}
      \centering
      \input{paper_slide_overlays.tex}
    \end{column}
  \end{columns}
\end{frame}

4. Custom RGB Colors

// RGB triples must be enclosed in quotes
slidegraph set, patterns("230 60 60" 11 "40 120 220" 01) off(0)

// Opacity modifier is automatically placed inside quotes: "40 120 220 %0"
slidegraph, stub(rgb_demo) : twoway ///
    (scatter price mpg if foreign==0, mcolor("230 60 60"))       ///
    (scatter price mpg if foreign==1, mcolor("40 120 220")),     ///
    title("Price vs MPG with Custom RGB Colors")

5. Layered Bar Charts and Box Plots

slidegraph set, colors(navy cranberry) cumulative

// Works with graph bar, graph box, graph hbar, etc.
slidegraph, stub(demo_bar) : graph bar (mean) price (mean) mpg, ///
    bar(1, color(navy)) bar(2, color(cranberry))                ///
    title("Average Price and MPG Comparison")

Stored Results

slidegraph subcommands store values in r():

slidegraph

slidegraph set

slidegraph export


Author & Support

License

MIT License. See LICENSE for details.