I don't have a feeling for this as a single
problem, so I am not clear there is a single
solution. It sounds as if you want a trace without
a trace, and I am not sure how far you can get that.
As occasional questions on Statalist underline,
some software's idea of a trace back includes something
like
error in program foo at line 29
called by program bar at line 367
called by program bazz at line 61
...
and no doubt programmers in such software make
what they can of that. I am sure that StataCorp
could have written something similar had they wanted
to.
Anyway, something like
local X = 1
forval x = 1/100 {
...
local ++X
}
di `X'
lets you inspect the loop number on exit but
it seems from your post that you may well know that.
An orthogonal comment is that hundreds of lines of
code may call for bundling into programs. In that case
the many possible lines of -display- may reduce to far fewer.
Nick
[email protected]
Julian Reif
> I often write code that contains very long for loops, e.g.
>
> forval x = 1/100 {
> [hundreds of lines of code]
> ...
> }
>
> If there is an error somewhere in the loop, Stata reports the
> error type but does not tell me what line it occurred on. To
> get around this, I frequently execute the command -set trace
> on-, which will tell you exactly what line of code the error
> occurred on. However, trace by default steps into each
> command (and subcommand) called inside the loop. This slows
> down execution and also displays lots of information I don't
> care about. Executing -set tracedepth 1-, which instructs
> Stata to only step down one level into each command,
> mitigates the situation but still displays more information
> than I'd like.
>
> What I want to be able to do is to -set tracedepth 0-, which
> would trace the lines of my for loop without stepping into
> all the commands, but Stata does not allow this. Is there a
> technical reason why this is so? Are there any alternatives
> (besides writing lots of -display- lines)?
*
* 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/