Keeping a Log in Stata

Stata makes it easy for you to keep track of what your doing. This is useful if you need to reproduce the analysis you have been doing, and it is useful for others looking at your analysis to understand what you have done. It also allows you to analyse errors in your data, and you can see the changes to your data made by your analyses. It is a very important tool that you should engage at the beginning of every Stata session.

There are two different logs that you can keep. The first log is engaged using the cmdlog command, and this will log all your commands in a .txt file. However, it will not keep track of your results or your data throughout the analysis. To do this you use the log command, which will keep track of both the commands and the outputs from your analyses.

How to Use:

To open a command log (stores commands only):

To close a command log:

To open a full log (includes results pane output and commands):

To close a full log:

Always remember if you want to save any file somewhere other than your current working directory you must specify the full path before the file name (e.g. C:\Users\filename instead of filename). Any path or file name that contains spaces must be enclosed in double-quotes for Stata to recognise it.

Worked Example:

I am going to run through a few simple analyses using the auto dataset, and I’m going to save everything in both a cmdlog and a log. I will attach the command log file and the full log file at the end of this post. The cmdlog default is to save as a .txt file, and the log default is to save as a .smcl file. For this analysis I am going to save both log files as text files. For the full log file this requires me to specify that I want it to save as a text file.

In the command pane I type the following:

Logging is very useful feature that will save everything you see in the results pane of Stata. However, the log does not save graph outputs. If you want to keep track of your graphs as well, you can save them when you create them, and then embed a link which will save in the log and you can click on it to see the graph when looking through the log.

I included several commands in my example above that illustrate how this works. First you create the graph and give it a name as an option which I did with the histogram command. Then you use the graph save command with the name of the graph and the filename you would like to save it under. Finally you use the display command to display a link to the location of the file, which someone looking at the log file would be able to click on (provided they have access to the location you saved the file). This link will only be clickable in the .smcl version of the full log file. In the command log file and the text version of the log file this link does not work.


The command log text file can be found here

The full log text file can be found here

81 views0 comments

Recent Posts

See All