What a log file does and why you need one
A log file in Stata is a text record of everything you type and everything Stata shows you in return. When you save a log file, you create a permanent copy of your work — the commands you ran, the results they produced, and any error messages. This matters because you can close Stata, come back weeks later, and still see exactly what you did and what happened.
Log files are especially useful when you are working with data for a report, a thesis, or a class assignment. Instead of trying to remember which commands you used or copying results by hand, you have a complete record you can reference, share with an advisor, or include in your documentation. The log file is plain text, so you can open it in any text editor — Notepad, Word, or the same program you use to write emails.
Key Takeaways
- Start a log file with the command log using filename.log at the beginning of your Stata session, replacing "filename" with a name that describes your work.
- Everything you type and every result Stata produces will be recorded in the log file from that point forward until you close it.
- Close the log file with the command log close when you finish your work, or Stata will close it automatically when you exit the program.
- Log files save to your current working directory by default, but you can specify a different folder path if you know where you want the file to go.
Starting a log file with the basic command
To begin recording your work, type the command in Stata's Command window (the white box at the bottom of the screen where you enter commands). The simplest version is:
log using mywork.log
Replace "mywork" with whatever name makes sense for your project — something like "analysis.log" or "homework_chapter3.log" works well. Stata will create a file with that name and the .log extension. From this moment on, every command you type and every result Stata displays will be written to that file.
If you run this command and a file with that name already exists, Stata will stop and ask what you want to do. You can replace the old file, append new results to it, or cancel and pick a different name. Most of the time you will want to replace it if you are starting fresh work, or append if you are continuing a session you paused.
Specifying where the log file saves
By default, Stata saves the log file in your current working directory — the folder Stata is currently looking at for files. If you are not sure where that is, type pwd (print working directory) in the Command window and Stata will tell you the folder path.
If you want the log file to save somewhere else, include the full path in your command. On Windows, that looks like:
log using "C:\Users\YourName\Documents\mywork.log"
On Mac or Linux, it looks like:
log using "/Users/YourName/Documents/mywork.log"
The quotation marks are important if your folder names contain spaces. If you are not comfortable with file paths, the easiest approach is to use the File menu: click File, then Change Working Directory, navigate to the folder where you want to save, and then use the straightforward log using filename.log command.
Choosing between .log and .smcl format
Stata can save log files in two formats: plain text (.log) or Stata markup (.smcl). The .log format is simpler and opens in any text editor. The .smcl format preserves formatting like bold text and colors, but only opens properly in Stata or a few specialized viewers.
For most purposes, .log is the right choice — it is readable anywhere and takes up less space. If you want .smcl instead, use the command:
log using mywork.smcl, replace
The word "replace" tells Stata to overwrite the file if it already exists. You can also use "append" to add to an existing file instead of replacing it. For a first log file, stick with .log unless you have a specific reason to use .smcl.
Closing the log file when you finish
When you are done working, close the log file with the command:
log close
This tells Stata to stop recording and finalize the file. The log file is now complete and ready to open, read, or share. If you forget to close it and just exit Stata, the program will close the log automatically, so your work is not lost — but it is good practice to close it yourself so you know the file is finished.
If you started multiple log files in the same session (which is uncommon), you can close a specific one by name:
log close mywork
Or close all open logs at once with log close _all.
Viewing and using your log file after Stata closes
Once you close Stata, your log file is a regular text file sitting in the folder you saved it to. Open it with any text editor — double-click it in your file explorer, or right-click and choose "Open with" and pick Notepad, Word, or whatever program you use for text.
The log file shows your commands and results in the order they ran. You can search it, copy sections of it, print it, or email it to someone else. Many people print their log files as part of homework or thesis documentation to show their work. If you want to clean it up before sharing — removing mistakes or sensitive information — you can edit it in any text editor and save the changes.
Frequently Asked Questions
What if I want to add to a log file I started before?
Use the command log using filename.log, append instead of replace. Stata will add new results to the end of the existing file rather than overwriting it. This is useful if you close Stata and come back to the same project later.
Can I see the log file while Stata is still running?
Not while Stata is still recording to it — the file is locked. Close the log with log close, open it in a text editor to read it, then start a new log with log using if you want to keep recording. Alternatively, you can pause recording with log off and resume with log on without closing the file.
What happens if I forget to close the log file?
Stata closes it automatically when you exit the program, so your work is saved. However, it is better to close it yourself with log close so you know exactly when the recording stopped and the file is finalized.
Can I use a log file to run the same commands again later?
Not directly from the .log file — it contains results mixed in with commands. Instead, save your commands in a .do file (a Stata script file) using File > New > Do-file. A .do file contains only the commands, which you can run again anytime. Many people keep both a .do file for their code and a .log file for their results.