Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Debugging: reporting line number of loop or do-file causing error


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: Debugging: reporting line number of loop or do-file causing error
Date   Thu, 29 Jul 2010 11:12:25 -0400

As others have noted, what you're doing is about the only
alternative to -set trace on-. However, it's possible to be
a bit smarter about it:

----------------------------------------------
local showi "*"
local showi di "Now executing line "

local i 1
forval j = 1/100 {
     `showi'`i++'
     ...some command here...
     `showi'`i++'
     ...some command here...
     ...etc...
 }
----------------------------------------------

The point being not only to save typing but also that you can comment
out the second -local- statement when you don't want to see the
line numbers anymore.


hth,
Jeph


On 7/29/2010 7:05 AM, Aleksander Rutkowski wrote:
Hello,

Is there any convenient way to make Stata report (together with an
error message) the line number of a loop or a line number of a do-file
which is causing an error?  In general, I think this is an important
feature needed for efficient debugging.

When loops are executed, the commands are not reported in the results
window, so it is difficult to quickly identify which command causes an
error. So far, I used the following solution, but it is not very
convenient:

local i 0
forval j = 1/100 {
    local ++i
    di "Now executing line `i'..."
    ...some command here...
    local ++i
    di "Now executing line `i'..."
    ...some command here...
    ...etc...
}

Alek
*
*   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/

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index