help for dolog and dosmcl (Roger Newson)

Execute commands from a do-file, creating a text or SMCL log file

dolog filename [ arguments ] [ , nostop ]

dosmcl filename [ arguments ] [ , nostop ]

Description

dolog and dosmcl (like do) causes Stata to execute the commands stored in
filename.do as if they were entered from the keyboard,
and echos the commands as it executes them,
creating a text log file filename.log (in the case of dolog)
or a SMCL log file filename.smcl (in the case of dosmcl).
If filename is specified without an extension,
then filename.do is assumed.
If filename is specified with an extension other than .do,
or with no extension,
then the log file will still have .log or .smcl as its extension,
so dolog and dosmcl will not overwrite the original do-file.
Arguments are allowed (as with do or run).

Options

nostop allows the do-file to continue executing even if an error occurs.
Normally, Stata stops executing the do-file when it detects an error
(nonzero return code).

Remarks

The original version of dolog was an example given as dofile
in a Stata NetCourse. This version is slightly improved.

Note that a do-file should nearly always start with a version statement
at or near the top.
This is because, nearly always, we prefer the do-file to run
in the Stata version in which it was written, even if the version of Stata
has been upgraded.
This practice also ensures that, if the do-file is run using dolog or dosmcl,
then it is run under its own Stata version,
and not under the Stata version of the current version of dolog or dosmcl.

An exception to this rule occurs when the do-file is a
certification script.
For these, it is best to use the version: prefix with dolog.
For instance, to run a certification script dolog.do
under Stata Version 16,
the user should type

. version 16: dolog dolog

and dolog.do will be executed under Stata Version 16.

dolog and dosmcl are recursive,
meaning that a master do-file input to dolog or dosmcl
may contain dolog or dosmcl commands
that call other do-files (known as servant do-files).
However, it is not usually a good idea to do this,
because the same output will then appear both in the log file for the master do-file
and in the log files for the servant do-files,
consuming disk space.
If the user wants to run a master do-file calling a sequence of servant do-files,
then the user should usually use the do command to call the master do-file,
which should contain multiple dolog or dosmcl commands calling the servant do-files.
This practice also makes it easy to test the servant do-files one by one,
before executing the whole sequence using the master do-file.

Examples

. dolog trash1

. dosmcl trash1

. dolog mycom argone argtwo

Author

Roger Newson, King's College London, UK.
Email: roger.newson@kcl.ac.uk

Also see

Manual: [R] do, [R] doedit, [R] log, [P] smcl, [P] version

Help: [R] do, [R] run, [R] doedit, [R] log, [P] smcl,
[P] version, [P] cscript
p_end}