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]

Re: st: Split code into programs or .do files?


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: Split code into programs or .do files?
Date   Mon, 2 Jul 2012 09:06:57 +0200

On Fri, Jun 29, 2012 at 8:18 PM, Richard Herron wrote:
> Yesterday Tyler Cowen linked to a code guide for research
> assistants at the University of Chicago Booth School of Business.
> 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

> 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?

The idea of splitting up code in smaller more manageble pieces is I
think good advise. However, I don't think there is much added value in
creating these blocks of code as separate programs and than calling
these programs. The only thing it does is mark specific bits of code
as belonging together, which can be done more clearly by either
storing those bits in a separate .do file, or, for smaller
"sub-blocks" of code, using comments. The creation of separate
programs only adds extra layer of complexity when debugging the code
without any benefit

> Are there economists that share the entirety of their Stata code
> for papers to learn best practices?

Uli Kohler puts the .do files for all his publications online:
http://www.wzb.eu/de/personen/ulrich-kohler?s=12918

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------
*
*   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