How to create a do-file in STATA?

By Indra Giri & Priya Chetty on November 24, 2016

Do-file is an interface in Stata which allows the researcher to compile all the commands and results in one place. Once the commands are stored in the do-file, one does 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 a new window (See below):
Using do file allows the researcher to run all the commands at once
The 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 “Execute” as shown below:
Along with command , comments can also be stored in do file
Copy the command in the do-file
  1. The 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.

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.