Joseph Nathan Cohen

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

Using Log Files in Stata

Short video explaining how to use log files on the statistical platform Stata. From 2012.

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 discuss the use of log files in Stata. By the end, you’ll understand what a log file is, its significance, and the methodology behind its creation and usage. A log file is essentially a text document that captures everything displayed in Stata’s results window. This encompasses both the commands you input and the results you receive. So, why are log files important? There are several compelling reasons: Retrace Steps: Log files provide an avenue to trace back your actions. If you’re unsure about how you achieved a certain result or your computer unexpectedly shuts down, a log file can be a lifeline to recover your workflow. Transparency: They enhance the transparency of your analysis. If there are questions about your results, you can share your log file which provides a comprehensive record of your analytical steps. To initiate a log file, you’ll use the command: log using “[filename].txt”, text append Where “filename” is the desired name for your log file. The “text” command ensures the file is saved in a universally readable plain text format, while “append” dictates that if a log file with the same name exists, Stata will append new content to it. Alternatively, using “replace” will create a new log file, discarding the old one. To see this in practice: First, set your directory to where you wish to save the log file. Then, input the command: log using “my_log_file.txt”, text append Stata will confirm that logging has commenced. Once you’ve conducted your analysis, such as loading data and summarizing variables, you can close the log file with: log close This log can now be located in the specified directory, presenting a record of all operations conducted. To view it, simply open the text file, which might be read through any text-reading program like Notepad or Microsoft Word. In conclusion, log files are invaluable tools to monitor your Stata activities. To initiate one, the syntax is: log using “[filename].txt”, text append To conclude it: log close Should you need a refresher on using the log command, simply type: help log in the Stata command window. For more insights, please visit josephinecohen.org.