4 [ U ] 15 Saving and printing output—log files
. translate session.smcl session.log
file session.log already exists
r(602);
If the file does already exist and you wish to overwrite the existing copy, you can specify the replace
option:
. translate session.smcl session.log, replace
See [R] translate for more information.
On Windows and Mac, you can also convert your SMCL file to a PDF to share it more easily with
others:
. translate session.smcl session.pdf
See [R] translate for more information.
If you prefer, you can skip the SMCL and create text logs directly, either by specifying that you
want the log in text format,
. log using session, text
or by specifying that the file to be created be a .log file:
. log using session.log
15.1.2 Appending to an existing log
Stata never lets you accidentally write over an existing log file. If you have an existing log file
and you want to continue logging, you have three choices:
• create a new log file
• append the new log onto the existing log file by typing log using logname, append
• replace the existing log file by typing log using logname, replace
For example, if you have an existing log file named session.smcl, you might type
. log using session, append
to append the new log to the end of the existing log file, session.smcl.
15.1.3 Suspending and resuming logging
Once you have started logging your session, you can turn logging on and off. When you turn
logging off, Stata temporarily stops recording your session but leaves the log file open. When you
turn logging back on, Stata continues to record your session, appending the additional record to the
end of the file.
Say that the first time something interesting happens, you type log using results (or click on
Log and open results.smcl). You then retype the command that produced the interesting result (or
double-click on the command in the Review window, or use the PgUp key to retrieve the command;
see [U] 10 Keyboard use). You now have a copy of the interesting result saved in the log file.
You are now reasonably sure that nothing interesting will occur, at least for a while. Rather than
type log close, however, you type log off, or you click on Log and choose Suspend. From now
on, nothing goes into the file. The next time something interesting happens, you type log on (or
click on Log and choose Resume) and reissue the (interesting) command. After that, you type log
off. You keep working like this — toggling the log on and off.