• Laura Whiting

Stata Logs - How to Set Up an Automatic Log

Stata contains a log feature which allows you to keep track of the steps you’ve taken during your analysis and the results you obtained. Unfortunately, you have to remember to open and close this log at the beginning and end of each session of Stata. It can be quite frustrating to find you’ve gotten half-way through an analysis and you’ve forgotten to activate your log. However, you can set up a file called “profile.do” in your User folder (mine is C:\Users\LauraWhiting). Your “profile.do” can be used to save a set of commands you would like Stata to run every time it starts up.


In this post we show you how to add log commands to your profile.do. We will show you how to add time as well as date to your log name, as well as how to get Stata to ask you for your project name on startup and add that to the log file name. We also get Stata to tell us where it has saved the log so we know where to find it later.


How to Use:

Go to your User folder (“C:\Users\Username” for Windows or ~ /Documents” for Mac). If there is already a “profile.do” in your user/documents folder you can open it to edit it, otherwise you need to create a new profile.do. To create a new profile do-file you can open a new do-file in Stata and save it as profile.do in the correct folder. Once you have your profile.do you enter the following commands into it:

Note: This will prompt you to enter a name (e.g. project01) so that the name of the log file becomes similar to the following “project01-21 Nov 2018.smcl”. This filename tells you what project it is for (assuming you give a name when you first open Stata), and the date the log was started (e.g. 21 November 2018). If you just press the Enter key without inputting a name the "default" text given in the above code will be used as the name. So you would get “default-21 Nov 2018.smcl” instead. As the above commands are just an example, you may make “default” whatever string you wish.


Worked Example:

Below I have included the commands I have in my “profile.do” and I show what happens when I open Stata with this profile.do in place.


These are the commands in my profile.do:

When I open Stata it automatically works through my profile.do and prompts me to enter a project name as I start. If I just press enter it will use “Tech Tip” as my project name. In this case I name my project as shown below:

This is the results screen I get every time I open Stata. As you can see I am prompted to enter a project name before I start loading my dataset or beginning my analysis.

This is the screen after I have given a project name. In this case I have called my project “Log Tech Tip”. Displayed below that is the folder where my log has been saved, and you can see the log has been engaged in the bottom right corner of the results screen in Stata. When I open the “Statalogs” folder in my “Documents” folder I find the following log file: “Log Tech Tip-22 Nov 2018.smcl”. This tells me I started my analysis for project name “Log Tech Tip” on 22 November 2018.

28 views

© 2020 by Survey Design and Analysis Services. 

  • LinkedIn
  • Facebook
  • Twitter
  • YouTube