Statalist


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

Re: st:tips to manage multiple do files?


From   Neil Shephard <nshephard@nhs.net>
To   statalist@hsphsun2.harvard.edu
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 (http://www.cygwin.com) 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...

master.do A main script that simply callse the following subsequent scripts in turn.
prep.do Script to read in, clean, tidy, and label the data, deriving any variables that are required
analysis.do 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)
results.do Uses the results data sets to generate tables and graphs for input into documents/reports

Neil

***********************************************************************
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
to: www.connectingforhealth.nhs.uk/nhsmail
***********************************************************************

*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index