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

Re: st: Stepping through do file

From   "Michael Blasnik" <>
To   <>
Subject   Re: st: Stepping through do file
Date   Sat, 29 Mar 2008 13:10:48 -0400

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)'"'
file read `hdl' line
file close `hdl'

It might be better to just be able to quickly edit your do files to add -pause- every other line (or every 3 lines or 4 lines etc..), which is what addpause.ado 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 run 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

----- Original Message ----- From: "Buzz Burhans" <>
To: <>
Sent: Saturday, March 29, 2008 11:51 AM
Subject: RE: st: Stepping through do file

Thanks Rajesh and Rich.

I am aware -pause-, and have used it extensively to accomplish this - but I
have a set of do files that is thousands of lines of code long in total, and
some do files call other do files. Using -pause- requires huge amounts of
time to put in the pauses at the appropriate places over thousands of lines,
and then later I need to clean up the files and remove the pauses - I don't
want to remove all the pauses later, because a few are needed in the program

So another approach, such as Rajesh's mention of using -F8- in Excel, would
be helpful.

Any other approaches to stepping through ??


Buzz Burhans, Ph.D.
*   For searches and help try:

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