How to create a do-file in STATA?

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

Senior Analyst at Project Guru
He completed his Masters in Development Economics from South Asian University, New Delhi. His areas of interest includes various socio development issues like poverty, inequality and unemployment in South Asia. Apart from writing for Project Guru he loves to travel and play football in his spare time.
Indra Giri

Latest posts by Indra Giri (see all)

Discuss