[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st:tips to manage multiple do files?

From   Neil Shephard <>
Subject   Re: st:tips to manage multiple do files?
Date   Fri, 19 Sep 2008 09:34:43 +0100

Man Jia wrote:
Hi all,

I was wondering if anyone could share any tips of managing many do files for one research project. Thanks for your help!
(1) How to make it easy to find some specific work in several do files?

Now I have to open most of them to see if the file has the part I'm looking for. The thing is, it is kind of hard to remember clearly the content of each file after even two or three days not working with them. I tried to write outline in the beginning of each file, but I have to open each of them to get the outline.
I find searching for specific work in text files pretty easy using commands such as 'grep' which searches specified text files for regular expressions. It has a heritage from *NIX systems (UNIX/BSD/Linux), but even if your using Windows you can install Cygwin ( and have the power of this command (and many other very useful and powerful commands). You can then use a specific comment style for your outline and simply search on that regular expression to get the outline without having to open the file up. There are various useful flags to this command such as '-R' to search recursively '-A #' / '-B #' which will output # lines After /Before the matched regular expression and many many more that are detailed in the help that comes with it.

(2) detailed comments in do files
For me it's useful to have detailed comments to explain what I'm doing in most parts in a do file. Those details include what the commands are doing, anything I should be careful with in future, sources I get the ideas, why the alternative ways are not good, summary of the results..... But a do file has limitation of number of lines in it. So, Writing a lot of comments means I have to create many do files. So, is there any good habit to deal with this? Is it better that in do files just add concise comments and take notes in other files?
I too tend to write fairly detailed comments in my do-files. There's not much to get around this, but over the years as my knowledge and understanding of Stata commands and syntax has developed I find that I write less verbose comments about what a particular command(s) is doing. I don't think that just because you're writing lots of comments you have to write lots of do-files.

Personally I tend to divide my scripts into three classes for any given piece of work, and will give them names such as... A main script that simply callse the following subsequent scripts in turn. Script to read in, clean, tidy, and label the data, deriving any variables that are required The main bulk of the analysis, which will save results to Stata formatted data sets (sometimes multiple analysis files depending on how complex the analysis is) Uses the results data sets to generate tables and graphs for input into documents/reports


This message may contain confidential and privileged information.
If you are not the intended recipient you should not disclose, copy
or distribute information in this e-mail or take any action in reliance
on its contents. To do so is strictly prohibited and may be unlawful.
Please inform the sender that this message has gone astray before
deleting it. Thank you.

2008 marks the 60th anniversary of the NHS. It's an opportunity to pay
tribute to the NHS staff and volunteers who help shape the service, and
celebrate their achievements.

If you work for the NHS and would like an NHSmail email account, go

* For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index