From the course: Introduction to Stata 15

Log files - Stata Tutorial

From the course: Introduction to Stata 15

Start my 1-month free trial

Log files

- [Instructor] Log files allow you to record your Stata session into something called a log file. By default, Stata does not start a log file. You'll need to tell it manually to start one. So in this session, we'll explore how to start a log file, how to view a log file, both within Stata and outside Stata, and how to amend or replace a log file. We're going to introduce the log command that starts, stops, and amend log files. We'll also look at the view command to view log files. And finally, we're going to look at the translate command, that allows you to convert Stata's default log format into something that other text editors can read. So let's head off to Stata and explore how to log our sessions. Imagine that we're about to start a new analysis session, and that we want to record all our work. Well, we can start a log file by typing log using and then giving the log file a name. In this case, let's call it log1. We can now execute this, and that will start a log file. Anything we now type will be saved to that log file. So as an example, let's load up some training data very quickly, and let's do a summary of this training data. We now have some numbers, we have some statistics, and lets assume we are now finished with our work. How can we close the log file? Well we can close the log file by typing log close and then executing that. Now that we are finished, how can we view the log file? Well there are two ways. You can either click on the file menu, going down to log and then viewing the relevant file, or we can call the view command and simply type the file name of the log file. In this case, log1, and we do have to give it a file type, which in this case is smcl. And by executing this, we can now see our previous log file. If we wanted to continue writing into this log file, then we can call up on the option append. Goes a little bit like this: log using log1 and then append. Anything we now type will be appended to the previous log file. If we wanted to replace the log file, we can call up on the option replace. Finally, if you want to view a log file with a different text editor, you'll first have to translate the smcl file, which stands for Stata mark up and control language, into plan text. You can do this by using the translate command. Translate log1.smcl to log1, and in this case the file extension you want to use is .log. Execute that, and then you can now navigate to the log1.log file and open this in Word, Notepad, or something else. So let's take a look, here it is. I will click on it, and you can now view your log file in Notepad. I strongly advise that you get into the habit of starting each Stata session with a log file. Should anything ever happen, you'll always have a record of what you've done.

Contents