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   Glenn Hoetker <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: Split code into programs or .do files?
Date   Fri, 29 Jun 2012 19:07:49 +0000

Both the PDFs and the associated discussion are great food for thought.  I suspect most important thing is to have a process and follow it consistently.  I suspect it also matters whether one is working primarily by oneself, as part of a small group, or as part of a large group.

My personal preference at this point is for one large document, mostly because it allows me to see everything at once.

My much less complete, timely and elegant set of suggestions to my doctoral students can be found the following PDF.  It no longer reflects my complete set of practices but is one way to think of structuring code. 

http://hoetker.faculty.asu.edu/phd_students/phd_students/files/e7f13735b94c2eb41343d11a85972ddc-4.html

I look forward to reading the comments of other researchers.

Glenn


Glenn Hoetker
Dean's Council Distinguished Scholar and Associate Professor
Department of Management, W.P. Carey School of Business
Affiliate Professor, Sandra Day O'Connor College of Law
Senior Sustainability Scholar, Global Institute of Sustainability
Faculty Fellow,  Center for Law, Science & Innovation
Arizona State University
 
http://hoetker.faculty.asu.edu
[email protected]
Tel: 480-965-4566

On Jun 29, 2012, at 11:20 AM, "Richard Herron" <[email protected]> wrote:

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

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