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

RE: st: Stepping through do file

From   "Buzz Burhans" <>
To   <>
Subject   RE: st: Stepping through do file
Date   Sat, 29 Mar 2008 19:11:03 -0400


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
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:
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
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] On Behalf Of Michael Blasnik
Sent: Saturday, March 29, 2008 1:11 PM
Subject: Re: st: Stepping through do file

Stepping through a do file would be a useful feature, but I'm not aware of
built-in way to do it.  Here are a couple of ado files that might be
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
the line to the screen and submits it to the command window.  It uses the
command to force a pause after each line.  It won't work within nested do
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)'"'
 file read `hdl' line
file close `hdl'

*   For searches and help try:

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