[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 14:17:59 -0400


Thanks very much for your response.  I just ran through one of my sets a set
of 6 do files with of do files -it took two days to get through and find and
fix the problem.  Now it runs fine -but I see that there is another
unexplained anomaly in the output data yet  -so I'll get a chance to try
your utilities out. 

I'm impressed by your creativity in approaching this problem. I like your
idea of creating a second copy as in your -addpause- program- it will.  I
have been adding -pause- to my files and following it with a comment:
L##_FileName; adding the Line numbers was useful in finding out where in the
file it was pausing and helped identify where the code was that need
examination - necessary because I was only adding pauses at places
(sometimes a fair distance apart) where I suspected I needed to look for
problems. This was part of why using manually entered -pause- was tedious.

By having them in at many short intervals using your -addpause- program I
should be able to see enough of the code as it runs to keep my bearings. 

I'm impressed by your creativity in approaching this problem. I envy your
programming ability-

Thanks again; I'll let you know how it works.


Buzz Burhans, Ph.D.

Dairy-Tech Group

Twin Falls, ID
Phone: 208-320-0829
Fax: 208-735-1289 

So. Albany VT
Phone: 802-755-6842


-----Original Message-----
[] 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'

It might be better to just be able to quickly edit your do files to add
every other line (or every 3 lines or 4 lines etc..), which is what
does.  By default it creates a new do file that just appends _pause" to the 
original file name.  So you can adjust your original do file and then just
addpause to create the pausing version for testing.

program define addpause
version 9.1
syntax using/, [every(integer 1) saving(str) ]
tempname hdl new
if "`saving'"=="" {
 local saving: subinstr local using ".do" ""
file open `new' using `"`saving'"', write text replace
file open `hdl' using `"`using'"', read  text
file read `hdl' line
local lnum=1
while r(eof)==0 {
 file write `new' `"`macval(line)'"' _n
 if mod(`lnum',`every')==0 {
  file write `new' "pause" _n
 file read `hdl' line
 local lnum=`lnum'+1
file close `hdl'
file close `new'
di "New do file created: `saving'"

Good Luck,

Michael Blasnik

*   For searches and help try:

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