Home  /  Resources & support  /  FAQs  /  Running Stata for Windows in batch mode

How do I run Stata for Windows in batch mode?

Title   Running Stata for Windows in batch mode
Author Jeremy B. Wernow, StataCorp

You can run large jobs in Stata in batch mode and create log files of all output in a few different ways on a Windows machine. We will explain three of these methods in this FAQ.

Method 1

One method is to click on the Start menu and select Run.... If your Stata installation directory is the default location of “C:\Program Files\Stata15”, then in the text box type

        "C:\Program Files\Stata15\StataMP" /b do c:\data\bigjob.do

This command tells Stata to execute the commands in bigjob.do, suppress all screen output, and route the output to bigjob.log in C:\Program Files\Stata15. You must give the full path of the Stata executable, and the log file will be saved in this installation directory.

The /b option will require that you click on OK before Stata can exit. If you use the /e option, no such action will be required.

        "C:\Program Files\Stata15\StataMP" /e do c:\data\bigjob.do

If you receive an error message of r(608) when attempting method one, then you do not have write permissions to the Stata installation directory. These permissions are needed to create the log file. In this case, you can use the second or third method and specify a path for the log file to be saved.

Method 2

If you would like the log file to be saved in a specific directory, then you can click on the Start menu and choose Run.... (Note: If you are working on Windows 7 or Vista and do not see the Run... button, then you need to click on Start -> All Programs -> Accessories -> Run. For Windows 8, go the the Desktop and use the Windows key + R on your keyboard to access Run.) Then, in the text box type


This will open a command prompt. You can then change the current directory to the one you want the log file saved to using the cd command. For example, typing the following will run bigjob.log, suppress all screen output, and route the output to bigjob.log in C:\data.

        cd C:\data
        "C:\Program Files\Stata15\StataMP" /e do c:\data\bigjob.do

You must specify the location of the Stata executable when using this method.

Method 3

Another common method is to use the Task Scheduler, which is installed on most Windows machines. You can usually find the Task Schedular by going to the Control Panel or by going to Start -> Programs -> Accessories> -> System Tools -> Task Scheduler. Once you have opened the Task Scheduler, click on “Create Task” and follow the steps of the Task Schedule Wizard to schedule a do-file to run in batch mode (must specify the /b or /e option). In the “Start in” text box, type the path where you would like the log file to be saved. When this file runs, all output will be suppressed and written to a log file that will be saved in the path specified.

You can read more about this feature in [GSW] B.5 Stata batch mode.