Introduction to Econometrics by James H. Stock and Mark W. Watson
STATA Tutorial to accompany Stock/Watson Introduction to Econometrics
Copyright © 2003 Pearson Education Inc.
Adopters of Stock/Watson, Introduction to Econometrics, may modify the information in this tutorial exclusively for the purpose of their classes.
STATA is a powerful statisticaland econometric software package. This tutorial is an introduction to some of the most commonly used features in STATA. These features were used for the statistical analysis reported in Chapters 3-11 of Introduction to Econometrics. This tutorial provides the necessary background to reproduce the results in Chapters 3-11 and to carry out related exercises. 1. GETTING STARTED STATA is availablefor computer systems such as Windows, Mac, and Unix. Your professor will tell you how to access STATA at your university. Most of you will be using STATA on Windows computers. To access STATA on these computers, you need to double-click on the STATA icon. This icon will probably be labeled Intercooled Stata X, where X is a number indicating the version of STATA available on your system. (All of theresults in Chapters 3-11 of Introduction to Econometrics were computed using Intercooled STATA 7.) Once you have started STATA, you will see a large window containing several smaller windows. At this point you can load the dataset and begin the statistical analysis. STATA can be operated “interactively” or in “batch mode.” When you use STATA interactively, you type a STATA command in the STATACommand window and hit the Return/Enter key on your keyboard. STATA executes the command and the results are displayed in the STATA Results window. Then you enter the next command, STATA executes it, and so forth, until the analysis is complete. Even the simplest statistical analysis will involve several STATA commands. When STATA is used in batch mode, all of the commands for the analysis are listedin a file, and STATA is told to read the file and execute all of the commands. These files are called do files by STATA and are saved using a .do suffix. For example, all of the STATA commands for the analysis in Chapter 4 of the text are contained in a file called ch4.do available on the Web site. When STATA executes this file, all of the empirical results for Chapter 4 are produced. Using STATAin batch mode has two important advantages over using STATA interactively. First, the do file provides an audit trail for your work. The file provides an exact record of each STATA command. Second, even the best computer programmers will make typing or other errors when using STATA. When a command contains an error, it won’t be executed by STATA, or worse, it will be executed but produce thewrong result. Following an error, it often necessary to start the analysis from the beginning. If you are using STATA interactively, you must retype all of the commands. If you are using a do file, then you only need to correct the command containing the error and rerun the file. For these reasons, you are strongly encouraged to use do files, and this tutorial will discuss STATA used in this way.
12. DO-FILE INGREDIENTS AND KEY COMMANDS A STATA do file has four different kinds of commands or ingredients: 1. Administrative commands that tell STATA where to save results, how to manage computer memory, and so forth 2. Commands that tell STATA to read and manage datasets 3. Commands that tell STATA to modify existing variables or to create new variables 4. Commands that tell STATA to carryout the statistical analysis
There are many commands within each category. A list of some of the most useful commands is given at the end of this tutorial. This section and the next will work through five examples of do files. After you have worked through these examples, you will have a good basic understanding of STATA. To begin, you need to download the do files. These files are called...