Stata Help

Logging Your Work in Stata

One of the most important things you can do when working with data is log your work. Without logging, hours of results can be quickly lost either by deliberate or indeliberate exit from the program.

There are two easy ways to start logging. The first of these is the command log using [log file's name] which begins logging all commands and results to a file named [log file's name].smcl to the working directory. If you want to stop logging temporarily, the command log off will pause the log and log on will unpause it.

These commands can also be achieved using the log button and its dropdown menu. logbutton

To stop logging and close the log, type log close into the command window.

This log can be printed using print [log file's name].smcl

If you prefer to view the log on your computer, you can type translate [log file's name].smcl [name].log , which will create an ASCII .log file named [name] which can be opened in word processors. Additionally, you can type type [logfile'sname].smcl and cause Stata to read the log file and show the contents in the Results window.

If you are working with the same data over a few sessions (as is often the case), you can use the command log using [logname], append which will pick-up the log named [logname] right where it left off.

A regular log will log all commands and result. If you want a second log of just commands, or are doing something where saving the results does not make sense (such as a Stata session wherein you generated new variables) you can also use the cmdlog using [name your file] This will create a .txt file that simply lists all your commands.

Finally, you can add comments to your logs as you go. To comment, type * or // followed by whatever comment you wish to make, or type your commetn within /* and */ delimiters. This will show up in both the cmd and regular log files, so use it anytime you think you might be confused in the future about why you did something (or to write yourself notes about things that need later verification). For example, say I load some new data and see that one of my means is a great deal higher than the possible range for the value. I might type myself a note that says  * check inc variable, seems high so that when I come back the next day, I will know the first thing I needed to do was look for typos in the "inc" variable.

Back