Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: Split code into programs or .do files?


From   Richard Herron <[email protected]>
To   [email protected]
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 marginalrevolution.com) 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.

http://marginalrevolution.com/marginalrevolution/2012/06/how-should-economists-write-code.html

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

* PROGRAMS
program main
prepare_data
run_regressions
output_tables
end
program prepare_data
X = format_x_vars
Y = format_y_vars
...
end
program format_x_vars
...
end
program format_y_vars
...
end
program run_regressions
...
end
program output_tables
...
end
* EXECUTE
main



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.)

Thanks!

Richard Herron
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index