Title | Running Stata for Unix in batch mode | |
Author | Alan Riley, StataCorp |
First, you should become familiar with do-files. Read [U] 16 Do-files and [R] do.
Now that you know what do-files are and how to run them interactively from within Stata, you can also use them to run background Stata batch jobs in Unix. There are two ways to do this:
stata -b do filename & or stata < filename.do > filename.log &
The first tells Stata to run in batch mode. Stata will execute the commands in filename.do and will automatically save the output in filename.log.
The second uses the Unix input redirection symbol to send each line in filename.do to Stata, just as if you typed that line interactively. Any output is redirected to filename.log.
The “&” at the end of each of the above examples tells Unix to run the command in the background, freeing up your Unix prompt.
Warning: In the second method, Stata does not know the commands it receives come from a file. As far as Stata is concerned, you are typing every command in filename.do on the Stata command line. If your do-file contains either the #delimit command or the comment characters (/* at the end of one line and */ at the beginning of the next), the second method will not work. We recommend that you use the first method: stata -b do filename &.
Finally, you may wish to start a batch Stata job, log off from your terminal, and log back in later to retrieve the output. To do this, you should preface either of the above methods with nohup
nohup stata -b do filename &
This command will prevent your Stata job from being killed when you log off. Type man nohup at your Unix prompt for more information.
Learn
Free webinars
NetCourses
Classroom and web training
Organizational training
Video tutorials
Third-party courses
Web resources
Teaching with Stata
© Copyright 1996–2024 StataCorp LLC. All rights reserved.
×
We use cookies to ensure that we give you the best experience on our website—to enhance site navigation, to analyze usage, and to assist in our marketing efforts. By continuing to use our site, you consent to the storing of cookies on your device and agree to delivery of content, including web fonts and JavaScript, from third party web services.
Cookie Settings
Last updated: 16 November 2022
StataCorp LLC (StataCorp) strives to provide our users with exceptional products and services. To do so, we must collect personal information from you. This information is necessary to conduct business with our existing and potential customers. We collect and use this information only where we may legally do so. This policy explains what personal information we collect, how we use it, and what rights you have to that information.
These cookies are essential for our website to function and do not store any personally identifiable information. These cookies cannot be disabled.
This website uses cookies to provide you with a better user experience. A cookie is a small piece of data our website stores on a site visitor's hard drive and accesses each time you visit so we can improve your access to our site, better understand how you use our site, and serve you content that may be of interest to you. For instance, we store a cookie when you log in to our shopping cart so that we can maintain your shopping cart should you not complete checkout. These cookies do not directly store your personal information, but they do support the ability to uniquely identify your internet browser and device.
Please note: Clearing your browser cookies at any time will undo preferences saved here. The option selected here will apply only to the device you are currently using.