do Files

Do your thinking in Stata code

stats
Stata
Author

Andy Grogan-Kaylor

Published

November 25, 2025

In my teaching, I often emphasize the importance of thinking in code, whether that code is Stata, or R, or some other program.

.do files are Stata’s way of storing code. I’ve provided an example .do file here: https://github.com/agrogan1/Stata/blob/main/do-files/README.md

%%{
  init: {
    'theme': 'base',
    'look': 'handDrawn',
    'themeVariables': {
      'primaryColor': '#FFCB05',
      'primaryTextColor': '#000000',
      'primaryBorderColor': '#00274C',
      'lineColor': '#00274C',
      'secondaryColor': '#00274C',
      'secondaryTextColor': '#000000',
      'tertiaryColor': '#F2F2F2',
      'tertiaryBorderColor': '#00274C'
    }
  }
}%%
block-beta
   columns 3
   A["have a <br>question"] space B["get <br> raw data"]
   space space space 
   D["process and <br>clean data"] space  C["select or <br>keep variables"]
   space space space 
   E["analyze <br>data"] space F["visualize <br>data"] 
   space space space 
   space space G["make <br>conclusions"]  

   A --> B
   B --> C
   C --> D
   D --> E
   E --> F
   F --> G