Johan Osterberg - Product Engineer

Working with log files in Stata

April 11, 2019

Log files in Stata can be useful if you want to keep track of your work over time, simply because it enables you to save your session for later retrieval. Of course, you can use .do files for this purpose as well, but they should be used to store real solutions, whereas log files are just, well, logs. In this example let’s crack open the nlsw88 dataset, start a log and run some commands:

log using mylog 
sysuse nlsw88, clear
tab industry
log close

The last, rather self-explanatory statement closes the log. Stata log files get the extension smcl which stands for Stata markup and control language. Now to view the log, type

view mylog.smcl

Your log file should now open in a new window including all activity from the previous session. Now for the next session you can either start a new file like the example above or you can append the one already created:

log using mylog, append

If you instead would want to write over the log file, you’d type

log using mylog, replace

It’s a good habit to start writing to a log file whenever starting a new Stata session,especially if you’re working on the command line.

Johan Osterberg

Written by Johan Osterberg who lives and works in Gothenburg, Sweden as a developer specialized in e-commerce. Connect with me on Linkedin