Statalist


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

RE: st: Stepping through do file


From   "Buzz Burhans" <buzzb3@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Stepping through do file
Date   Sat, 29 Mar 2008 19:11:03 -0400

Michael,

My apologies for my garbled earlier thank-you email - I was too rushed and
thus unclear, I should have been more careful.  

I think the -stepdo- approach is not going to work -I am not suggesting you
refine it, but only wanted to let you know, and hope that the exchange might
stimulate StataCorp to consider adding the capability to step through -do-
files line by line while keeping the do file active.

Anyway, I have tried -stepdo- and can't seem to get it to run correctly.  

The first run failed because there was a line at the top of the file
commented out as // text...; the results-screen display after running
-stepdo- with that line in the file were:

. stepdo using ...path...TDStages_History1v2.do
// ...path...TDStages_History1v2.do
unrecognized command:  / invalid command name
r(199); t=0.00 18:36:17


I think that Stata is unable to handle the -//-, as reported earlier in this
statalist post: http://www.stata.com/statalist/archive/2005-05/msg00115.html
Since my -do- files contain frequent comments, this probably renders this
approach unusable.


I later removed the commented out line, and it did two unexpected things;
1st, it ran multiple lines of the -do- file without stopping; second, it
failed on "cap nois log close":

. stepdo using
C:\ViewsVT\Stata\TDStages\HistoryReports\TDStages_History1v2.do
version 9.2
                        cap nois log close
unrecognized command:                   cap invalid command name
r(199); t=0.00 18:48:42

Seems it somehow doesn't recognize abbreviated commands like cap / -capture-
and disp / -display-

I suspect that the running of multiple lines instead of single lines could
be that the macro `hdl'  in the -stepdo- code does not seem to be identified
-but I am not sure.

Thanks very much for this.  I am going to try the -addpause- approach now.

Buzz

statalist@hsphsun2.harvard.edu] On Behalf Of Michael Blasnik
Sent: Saturday, March 29, 2008 1:11 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Stepping through do file

...
Stepping through a do file would be a useful feature, but I'm not aware of
any 
built-in way to do it.  Here are a couple of ado files that might be
helpful, 
but probably won't work for some more complicated situations.  Feel free to 
adjust them as needed.

First, stepdo.ado simply reads in a do file one line at a time and then
echoes 
the line to the screen and submits it to the command window.  It uses the
-more- 
command to force a pause after each line.  It won't work within nested do
files 
since they will appear as a single command.  Code could perhaps be added to 
check for "do" as the first word of any line and then call itself to run the

subroutine do file.

program define stepdo
version 9.1
syntax using
tempname hdl lin
file open `hdl' `using', read text
file read `hdl' line
while r(eof)==0 {
 di _asis `"`macval(line)'"'
 `macval(line)'
 more
 file read `hdl' line
}
file close `hdl'
end


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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