Differences between revisions 2 and 8 (spanning 6 versions)
Revision 2 as of 2021-03-16 18:28:54
Size: 475
Comment:
Revision 8 as of 2023-06-08 20:30:12
Size: 1132
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Log Files = = Stata Log =
Line 3: Line 3:
Stata outputs to a terminal emulator. Output can be recorded into a markup file, which can be rendered into file formats including raw text. The '''`log`''' command records commands and command output, and writes them to a log file.
Line 9: Line 9:
== Built-in Logging == == Usage ==



=== Rich Logs ===

Stata supports a rich log format, using the `.smcl` file extension.
Line 12: Line 18:
log using "path/to/file", replace log using "path/to/file.smcl", replace
log close
}}}
Line 14: Line 22:
// do something
Line 16: Line 23:

=== Text Logs ===

Use the '''`text`''' option.

{{{
log using "path/to/file.txt", replace text
log close
}}}

----



== Temporarily Disabling Logging ==

Some output should not be recorded. Try:

{{{
Line 17: Line 43:
di "Rather than running commands `quietly`, temporarily turn off logging. display "Rather than running commands quietly, temporarily turn off logging.
Line 19: Line 45:
}}}
Line 20: Line 47:
// do something else ----
Line 22: Line 49:
log close
translate "path/to/file.smcl" "path/to/file.log"
}}}


== Stored Results ==

`log` stores the following details:

 * log name in `r(name)`
 * log filename in `r(filename)`
 * logging status (on or off) in `r(status)`
 * log type (smcl or text) in `r(type)`

`log query _all` stores the number of open logs in `r(numlogs)`. For each open log, it stores the above details as e.g. `r(name1)`, `r(name2)`, and so on.

----



== See also ==

[[https://www.stata.com/manuals/rlog.pdf|Stata manual for log]]

Stata Log

The log command records commands and command output, and writes them to a log file.


Usage

Rich Logs

Stata supports a rich log format, using the .smcl file extension.

log using "path/to/file.smcl", replace
log close

Text Logs

Use the text option.

log using "path/to/file.txt", replace text
log close


Temporarily Disabling Logging

Some output should not be recorded. Try:

log off
display "Rather than running commands quietly, temporarily turn off logging.
log on


Stored Results

log stores the following details:

  • log name in r(name)

  • log filename in r(filename)

  • logging status (on or off) in r(status)

  • log type (smcl or text) in r(type)

log query _all stores the number of open logs in r(numlogs). For each open log, it stores the above details as e.g. r(name1), r(name2), and so on.


See also

Stata manual for log


CategoryRicottone

Stata/Log (last edited 2023-06-09 13:49:49 by DominicRicottone)