Johan Osterberg - Product Engineer

Using do-files in Stata

April 12, 2019

Using do-files (a text file with the .do extension) is the preferred way of working in Stata. They are simply text files containing executable Stata code, similar to what you would have in any programming language. Much for the same reasons it is preferable to store code to for example analyze large datasets in a do-file that you can just reuse over again like you would run a program in another language.

Where do-files are customized for one specific dataset, ado-files are used for global-level, extension code that are independent of specific datasets. The do-file editor can be opened by typing:

doedit 

In this file we’ll just stash a bunch of instructions, like so:

* load the national survey of women from 1988 and run some commands 
sysuse nlsw88, clear 
describe
tab occupation

Now this file can be stored and called upon when needed. Simply save the file as my-do-file.do and then just execute it:

do my-do-file

Johan Osterberg

Written by Johan Osterberg who lives and works in Gothenburg, Sweden as a developer specialized in e-commerce. Connect with me on Linkedin