Save a log file by opening the log dialog and choosing your location
A log file in Stata records everything you type and every result Stata produces during your session. To save one, you open Stata's log dialog, pick where to store the file, give it a name, and tell Stata to start recording. The file stays open until you close it — Stata will not automatically save it when you quit the program.
The log file is a plain text document. You can open it later in Notepad, Word, or any text editor to review your work or share results with someone else. Many researchers keep log files so they have a permanent record of exactly what they ran and what the output was.
Key Takeaways
- Open the log dialog by clicking File > Log > Begin in the menu bar, or type log using filename in the Command window.
- Choose a folder where you want to store the log file and give it a name — Stata will add the .log extension automatically.
- Close the log file when you are done by clicking File > Log > Close, or type log close in the Command window.
- A log file records your commands and results as plain text, so you can open it in any text editor after your Stata session ends.
- If you want to add to an existing log file instead of overwriting it, use the append option when you open the log.
Using the menu to open a log file
The menu method is the most straightforward if you are new to Stata. Click the File menu at the top of the Stata window, then hover over Log, and click Begin. A dialog box will open.
In the dialog, navigate to the folder where you want to save your log file. You can use the folder tree on the left side or click the folder icon to browse. Type a name for your log file in the File name field — do not include .log at the end, because Stata adds it automatically. Then click Save. Stata will now record everything until you close the log.
If you want to add new output to an existing log file instead of replacing it, check the Append box before clicking Save. Without this box checked, Stata will overwrite any log file with the same name.
Using the Command window to open a log file
If you prefer typing commands, you can open a log file directly in the Command window. Type log using filename and press Enter. Replace filename with the name you want — for example, log using myanalysis. Stata will create the log file in your current working directory.
To save the log file to a specific folder, include the full path: log using C:\Users\YourName\Documents\myanalysis on Windows, or log using ~/Documents/myanalysis on Mac. If the path contains spaces, put the whole thing in quotes: log using "C:\Users\Your Name\Documents\myanalysis".
To append to an existing log file instead of overwriting it, type log using filename, append. This adds your new commands and results to the end of the file.
Close the log file when you are finished
Stata keeps the log file open and recording until you tell it to stop. To close it, click File > Log > Close in the menu. Or type log close in the Command window and press Enter.
When you close the log file, Stata stops recording. The file is now saved to disk and you can open it in any text editor. If you close Stata without closing the log file first, the log file will still be saved — Stata closes all open logs when the program shuts down.
What happens if you do not close the log file
If you forget to close the log file and try to open a new one with the same name, Stata will show an error message saying the file is already in use. You have two choices: close the first log file, or use a different name for the new one.
To close a log file that is still open, type log close in the Command window. If you have multiple log files open at once (which is uncommon), you can close a specific one by typing log close logname, where logname is the name you gave it when you opened it.
View your log file after Stata closes
Once you close the log file, you can open it like any other text document. On Windows, right-click the .log file and choose Open with, then select Notepad or Wordpad. On Mac, double-click the .log file and it will open in TextEdit. You can also drag the file into Word or Google Docs if you want to format it or share it.
The log file contains plain text, so it will look the same no matter which program you open it in. Everything you typed and every result Stata produced will be there in order, from the moment you opened the log until the moment you closed it.
Frequently Asked Questions
Can I open a log file while another one is already open?
No. Stata will not let you open a second log file until you close the first one. If you try, you will see an error message. Type log close to close the current log, then open a new one.
What if I want to save my log file as a PDF or Word document?
Open the .log file in Word or Google Docs and save it in the format you want. The log file itself is always plain text, but once you open it in another program, you can convert it to PDF, .docx, or any other format that program supports.
Does the log file include graphs or charts?
No. The log file records only text — your commands and the text output. Graphs are saved separately. To save a graph, use File > Graph > Save in the menu, or type graph export filename.png in the Command window.
Can I edit the log file while Stata is still running?
You can open and read the log file in another program, but you should not edit it while Stata is still writing to it. Wait until you close the log file in Stata, then edit it if you need to.
What if I close Stata without closing the log file?
The log file will still be saved. Stata automatically closes all open logs when you quit the program. You can open and read the log file normally after Stata closes.