Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

Re: st: log file recording within loops

From   Michael Norman Mitchell <>
Subject   Re: st: log file recording within loops
Date   Sat, 20 Mar 2010 15:04:21 -0700

Dear Jan

I have frequently wished for the exact same thing. In SPSS there is "DO REPEAT" and "END REPEAT PRINT.", where the "PRINT" option specifies that each command generated by the loop is displayed, for example.


  I sometimes will fake this in Stata by typing, at the command window

. set trace on
. set tracedepth 1

  and then the contents of the loops are displayed, e.g.

--- ---
sysuse auto, clear
foreach v of varlist m* {
  summarize `v'
---- ---

do test

. sysuse auto, clear
(1978 Automobile Data)

. foreach v of varlist m* {
  2.   summarize `v'
  3. }
- foreach v of varlist m* {
- summarize `v'
= summarize make

    Variable |       Obs        Mean    Std. Dev.       Min        Max
        make |         0
- }
- summarize `v'
= summarize mpg

    Variable |       Obs        Mean    Std. Dev.       Min        Max
         mpg |        74     21.2973    5.785503         12         41
- }

end of do-file

Michael N. Mitchell
See the Stata tidbit of the week at...

On 2010-03-20 1.44 PM, Jan Stuhler wrote:
Dear all,

a question on log-files. Stata does not log any commands that are inside loops (it only logs the results/output). Since loops are usually all over in my do-files I end up having a long list of uninformative notices in my log-files.

I know that most people add comments (e.g. "di ....") in their do-files in order to keep track at which part of the loop their log-file is recording. I do not like this solution since it means a lot of additional typing and a potential source of typos. Is there any other solution, e.g. some sort of "noisily" command that forces Stata to log commands within loops?

Many thanks for any answers,
*   For searches and help try:
*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index