Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why does log do not print my commands?

    Context: I am working with confidential data, which requires me to log all of my commands and the output in a log file. They will not check my do files, just the logs.

    This used to work fine until they upgraded to STATA17. I am not sure why, but the log files do not log my commands anymore. Comments and output yes, commands no.

    Why is it happening? Is there a command to fix this?

    Sample code below

    Code:
    set more off
    
    foreach year in 1970 1980 1990 {
    capture log using "mylog.log", replace name(log_`year')
    
    di "* ---------------------------------------------------------------------------"
    di "* Comments "
    di "* ---------------------------------------------------------------------------"
    
    use "data`year'.dta", clear
    
    * Renaming variables
    rename thisvariable othername
    
    * di "Table One ---------------------------------------"
    reg y x [iweight=weight], r 
    
    }
    I want it to print everything, but the output from the log file is

    * ---------------------------------------------------------------------------
    * Comments
    * ---------------------------------------------------------------------------

    Table One ---------------------------------------
    [regression table]

    Note how in order for it to print the comments in the log file I have to use the display (di) command. The actual commands, like rename, reg and use, are not recorded.


  • #2
    Stata doesn't -log- commands inside a loop. You and I both wish there were an option to include those commands, especially for debugging. Often I see an error message for a loop with hundreds of lines, and there is no indication of which line the error refers to. You can

    Code:
    set trace on
    set tracedepth 1
    to get the comands in the loop, but possibly more than is needed or wanted.

    Three additional comments: (1) with the -log- command inside the loop, only the output from the last iteration is preserved. I should think you want to move the -log- command out of the loop. (2) The -name- option isn't doing anything here. (3) The -capture- of the -log- command sems like a bad idea. If -log- errors out, then the prior log is preserved, but the program runs to no particular purpose.

    Comment

    Working...
    X