Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Split code into programs or .do files?

From   Richard Herron <>
Subject   st: Split code into programs or .do files?
Date   Fri, 29 Jun 2012 14:18:21 -0400

Yesterday Tyler Cowen (econ prof at George Mason University and
blogger at linked to a code guide for research
assistants at the University of Chicago Booth School of Business. The
guide is by two noted economists (Matthew Gentzkow and Jesse Shapiro)
and very good.

I have a question about a code block that uses a program "main" to
call several sub-programs. I quote from page 11:

In long scripts, comments can be used to make clear how the code is
organized. In many languages, the
modular structure of the code makes clear how it is organized. This is
natural in Matlab, Java, etc. In Stata,
we might write

program main
program prepare_data
X = format_x_vars
Y = format_y_vars
program format_x_vars
program format_y_vars
program run_regressions
program output_tables

Is this conventional?

J. Scott Long's "Workflow of Data Analysis" suggests splitting code
into a series of .do files to be called by a master .do file. Is there
equivalence between these two approaches? Or does each have a best use
case? Are there economists that share the entirety of their Stata code
for papers to learn best practices? (I frequently come across .dta
files and Matlab code, but not Stata code.)


Richard Herron
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index