log
Records everything that appears on screen into a file.
What we have
log using,replace,close,offandon
Coming later
log using ..., text|smcl— there is one plain-text formatcmdlog, for a file of just the commands
How you write it
log using "file.log" [, replace] | log close | log off | log on
Square brackets mean optional. A vertical bar means choose one.
What it does
log using "run.log", replace, then work as normal, then log close. The file holds every command and every result, which is what you want when somebody asks six months later how a number was produced.
log off and log on pause and resume without closing the file.
Watch out. Close the log before you finish. A log left open may be missing its last lines.
Try it
Every example below was run after sysuse vira.sample02, clear.
. log using "run.log", replace
log: run.log opened on: 20 Sep 2026, 09:30:00
The same thing in pandas and in R
R
# no R form for `log` yet -- see docs/r-equivalents.md
. summarize age
Variable | Obs Mean Std. dev. Min Max
-------------+------------------------------------------------------------
age | 6,000 47.0195 18.76303 15 79
The same thing in pandas and in R
pandas
df[['age']].describe()
R
library(dplyr)
df %>% summarise(age_n = sum(!is.na(age)), age_mean = mean(age,
na.rm = TRUE), age_sd = sd(age, na.rm = TRUE), age_min = min(age,
na.rm = TRUE), age_max = max(age, na.rm = TRUE))
# This R was run in a real R (4.6.1) and gave the same numbers.
. log close
log: run.log closed on: 20 Sep 2026, 09:30:00
The same thing in pandas and in R
R
# no R form for `log` yet -- see docs/r-equivalents.md