Stata .do file template

Having a template for new .do files is an easy time saver. This template assumes you're running everything in one file, but this can be easily modified if you break your workflow into multiple do files such as 01_cleaning.do and 02_analysis.do etc with a primary .do file that runs all project .do files if needed. (For more on that type of work flow, check out Scott Long's The Workflow of Data Analysis Using Stata or see a slightly more involved example from Glenn Hoetker here).

Below you can download a copy of the .do file as well as see the contents.

* WORKING DIRECTORY
// use -pwd- and -cd- to access the project-level folder

cd XXXX/XXXX/				

* LOG START

capture log close
log using log/logXX.log, replace 

**# INFO

/*
  PROJECT: 	XXXX
  AUTHOR: 	XXXX
  DATE:		XXXX-XX-XX
  NOTE: 	XXXX
*/

**# BOILERPLATE

version 18.5            // Set version for compatibility
set more off            // Disable partitioned output
clear all              	// Start with clean slate
macro drop _all        	// Clear any macros
set varabbrev off       // Do not allow abbreviations of variable names
* set scheme stmono2	// Set graphs to black and white if desired


**# LOAD DATA


**# CLEAN DATA


**# ANALYIZE DATA


* LOG END

capture log close

There are many ways to break up sections in text files. In Stata, using **# creates a section bookmark available in the .do file editor equivalent to an H1. This can come in handy when you .do files start getting long.

A sub head can be created with **## and so on.

Feel free to use and modify for your needs. You can also use Stata projects with relative paths instead of manually setting the working directory to the project level folder. My folder typically looks something like: