Custom Commands

A collection of small commands and utility scripts written over the years. Each .ado file below has a matching .sthlp file, so once both are saved to your Stata PERSONAL directory, help commandname will work automatically.

Run sysdir in Stata to see where your PERSONAL directory is, then drop the downloaded file(s) there.

Data Summaries & Cleaning

dsum

Quick cursory summary of a variable list: total observations, missing count, % missing, and distinct values per variable, with an optional column for the sum.
dsum varlist [if] [in] [, sum] Download dsum.ado · Help file

varcheck

Builds a table showing the percent of observations missing for each variable in a varlist, broken out by another variable (e.g. survey wave or year). Useful for checking data availability across waves of a longitudinal survey.
varcheck varlist, by(varname) Download varcheck.ado · Help file

dummies

Creates a dummy variable for every distinct value of a string variable, cleaning spaces out of the generated variable names.
dummies varname Download dummies.ado · Help file

mencode

A sometimes-useful stand-in for encode when the values and their labels already exist side by side in the dataset. Reads the label text straight from the data and applies it as a value label to the numeric variable.
mencode varname, labels(varname) [labelname(string) force drop] Download mencode.ado · Help file

mklist

Takes a variable's distinct values and concatenates them into a single delimited string - useful for building an inlist() condition on the fly.
mklist varname [if] [in] [, delimiter(string) noquote] Download mklist.ado · Help file

transpose

Quick-and-dirty transpose of the whole dataset, run through a CSV round-trip, with the option to retain the first column as variable names.
transpose [, vars] Download transpose.ado

ts

One-line utility that displays the current date and time - a quick way to time how long a chunk of do-file code takes to run.
ts
Download ts.ado

Reshaping & Labels

supershape

An enhanced version of Stata's built-in reshape. Retains variable labels when reshaping wide-to-long, or assigns them when going long-to-wide, and can fill missing numeric values with zeros.
supershape wide|long stub, i(varlist) [j(varlist) keeplabels labels(varname) fill zeros string] Download supershape.ado · Help file

preserve_labels

collapse drops variable labels - this small wrapper saves them beforehand and reapplies them after. Pass your collapse statement in as a string.
preserve_labels "collapse (mean) mpg price weight, by(foreign)" Download preserve_labels.ado · Help file