Joseph Nathan Cohen

Department of Sociology, CUNY Queens College, New York, NY

Using Log Files in Stata

To see more about the “Teaching through YouTube” series.  For more, see this post.

Original Video Description

How to use log files in Stata.

Transcription (Auto-Generated)

in this video we’ll talk about how to use log files in Stata log files keep a record of all of the input and output that comes up in status results window first it helps you reproduce your work that means that if you find a good finding and you want to find out how you reach that finding you can go back through the log file and find the steps that brought you to where you want to be second it allows other people to check your work that’s useful when you want help from an outside consultant or if somebody wants details on how you got the findings that you got the command to generate log files is log this is the To Start a Log File syntax for beginning a log file to start a log file input these commands log space using space quotation mark the name you want to assign to your lock file dot txt close quotation marks comma text append with the space after the comma and a space after text for example if I wanted to call my log file data analysis I’d use the syntax log using data analysis txt in quotation marks comma text append your file name can have letters numbers and space is embedded in it by using the option text in this command you’re asking data to store your lock in a plain text file that can be opened on any computer without using this option you’ll require Stata to open up your log file the option append tells data to add any new input or output to the end of a log file that has the name that you want to assign to this log file in other words if you already have a log file called data analysis and you use the command append Stata will add any new input or output to the end of the log file you could instead use the option replace which tells Stata to erase the old copy and create a new one you can pause and Command restart a log file by using the commands log off and log on the command log off pauses the log files recording of your input and output log on resumes a paused log file to stop logging your input and To End Log File Recording output into the command log close let’s see what it looks like to use log files in a state a session I asked Stata to start a log session by typing in logged using open quotation marks and the name of the log file that I want I’m calling it my log file dot txt closed quotes comma text I hit enter and I get this message telling me that the log file has begun if I type in some analyses and close the log file I’ll see that the log files appeared on my working directory I can open it and see what I did in my stay the session I’m going to reopen the log file again and I’ll get this message I can type in more analyses and it will also be recorded if I type logoff it will pause the analysis while the log is off I’m going to run a tab a people citizenship and turn the log on that I’ll run a third variable I close the log file and if you look the table denoting citizenship and the sample isn’t recorded because the logging was paused a log file records a state of sessions Review input and output you begin a log file using the command logged using quotation marks the name of the log file again the name you want to assign to the log file dot txt close quotation marks comma text if you add the option replace you’re asking Stata to overwrite any log file that already exists with that name if you use append you’re asking Stata to add new input and output to the end of an existing log file to pause a log file type in log off to resume logging your session use the command log on and to close a log file use the command log close for more information on Stata logs type help log in the command window