How to create a do-file in STATA?

By Indra Giri and Priya Chetty on November 24, 2016

Do-file is an interface in Stata which allows the researcher to compile all the commands and results at one place. Once the commands are stored in do file, one do not need to enter the command again. One can simply run the do file and get all the results at once. Unlike SPSS wherein, the output sheet is automatically generated every time you run a test. All the commands and results in this file can be mailed together.

How to create a do-file?

  1. Open a do file by clicking on the tab encircled below:
Do file helps to store all the commands which can be run later
Do file tab in STATA
  1. The do-file will open in new window (See below):
Using do file allows the researcher to run all the commands at once
Interface of the editor
  1. Based on your previous analysis, you can either “Open” the existing do-files from “File” or can copy the command from the command window in the file.
  2. In order to run or execute the command saved in the do file, click on the “Execute” as shown below:
Along with command , comments can also be stored in do file
Copy command in do file
  1. Final step is to save it. In STATA do-file editor, click on “File” in the menu bar and click “save as”. The file is saved in “.do” format in the folder you wish to save it in.

Note: These files can be created and edited in text editors like notepad or word pad. However, they should be saved in “.do” format or else they will not run in STATA.

How to manage variables in STATA?How to do the correlation analysis in STATA?
Indra Giri
Latest posts by Indra Giri (see all)