The Do-File Editor - An Introduction

The “do-file editor” is a text editor that comes installed with Stata. It is named after what Stata calls a do-file, which is a type of text file that contains a list of Stata commands. Any simple text editor can be used to make a do-file. These files can be run as a batch job in Stata, meaning you can ask Stata to run all the commands in the file at once. This is useful for several reasons. First, if you run the exact same analysis multiple times you don’t have to keep writing out the commands, which will save you time. Second, if you run an analysis from a do-file your results are easily reproducible both by you, and by anyone trying to replicate your analysis. And third, if you need to change a part of your analysis you simply update the do-file and re-run it, rather than re-doing all the analysis in Stata to reflect the change.

When setting up a new do-file, it is generally advisable to state at the top of the file what version of Stata you were using at the time of creation. This is because Stata is backwards compatible, so a do-file you create now for Stata 15 will run in any future version of Stata – provided you specify the version it was originally written for.

How to Use:

Open your text editor of choice (eg. The “do-file editor” that comes with Stata or a .txt editor).

To access the do-file editor in Stata using the Stata menu: Window -> Do-file Editor -> New Do-file Editor, which can be seen in the image below:

This should open a new window that looks like the image below:

Once you have your text editor set up, you input your list of Stata commands making sure to put the version at the top. An example would be to input the following:

version 15

command 1

command 2

Then, to run your do-file in Stata:

If the do-file is saved in your current working directory:

Otherwise specify the file location:

Alternatively, you can choose the file for Stata to "do" through the Stata menu, shown in the image below:

Worked Example:

In this example I am going to save a small set of commands as a do-file and run that file through Stata. In my do-file I type the following:

Which you can see in the image of my do-file below:

I have saved this file under the name “mydofile” in my Documents folder, which is my current working directory. The file is attached here as a text document, which you can download and run if you wish.

To run the file, I type the following into the command pane:

Which produces the following output in the Stata results pane:

89 views0 comments

Recent Posts

See All