Using Stata for Quantitative Analysis. Kyle C. Longest
describes these procedures for Stata 13 and Stata 12. Starting from Chapter 2, the vast majority of operations and commands are similar across versions. And the text specifically notes any particular features that are different for previous versions.
When you open Stata, by double-clicking on the Stata icon, for the first time, you will see the screen as shown in Figure 1.1.
FIGURE 1.1 • BASIC STATA DISPLAY
There are five different windows on the screen.3
3This layout is what you would see if Stata was opened “right out of the box.” If you are working on a shared computer (or over a network), there is a chance that these windows have been moved, resized, or even deleted by another user, making what you see slightly different from the screenshot presented. If any of these windows are missing, you can click on the Windows tab, and then click on the desired window. You can also move these windows by simply clicking on them with your mouse and dragging them to the desired location.
1 Results Window: The Results window is where everything that Stata “does” will be displayed. Anytime Stata executes some operation, it will display that operation and its results in this window. These results, however, are not automatically saved. How to save these results is covered in the Data Management: Saving Results section of Chapter 3.
2 Review Window: The Review window contains a running history of all the operations that have been performed during the current session of Stata. Whenever you enter and execute a command, it will appear both in the Results window and in the Review window. The most useful aspect of the Review window is that it can be used as a shortcut to work with a previously executed command. When you click on a command in the Review window, that command will appear in the Command window, from which you can alter the command or simply rerun the same command. If the command is shown in red in the Review window, it means something is not quite right. We will discuss how to handle this situation in the 5 Essential Commands section of Chapter 2.
3 Variables Window: When you open a data file in Stata, the variables contained in that data set will be listed in the Variables window. This window can be used to scroll through and see all the variables that are contained in the active data. Whenever you click on a variable name listed in the Variables window, several characteristics of that variable are displayed in the Properties window. If you place your cursor over a variable, a small arrow will appear. By clicking on that arrow, the variable name will automatically appear in the Command window. Double-clicking on the variable will also place the variable name in the Command window. This window also lists the variable “Label,” which presents more detailed information about the variable. Labels are discussed in more detail in the Data Management: Working With Labels section of Chapter 3.
4 Properties Window: The Properties window provides details about the data set that is currently being used and any variable that has been selected (by clicking on it) from the Variables window. For the data, this window provides the file name, the number of variables that are included in the data, and the number of “observations” (e.g., survey respondents). For a given variable, the Properties window lists the variable name, its type, format, and value label. Details on each of these descriptors are discussed later in this chapter. By default, the Properties window is “locked,” meaning you cannot change any of these characteristics directly from the Properties window. Clicking on the padlock icon (located in the upper left corner of the Properties window), however, unlocks the Properties window and allows you to change the aspects of the variable simply by clicking on that property (e.g., the variable name). More details on this process are provided later in this chapter.
5 Command Window: The Command window is where you will enter the operations that you want Stata to perform, when using the “syntax” interface. Syntax, or code, is another term for Stata’s command language. These are the words that tell Stata what procedures to execute. Commands are entered, one at a time, in this window. After you type a command into the Command window, pressing the Enter key on your keyboard makes Stata execute the procedure that is defined by the Command. One helpful feature of the Command window is that you can scroll through previously executed commands by pressing the Page Up key. When you find the previous command you are interested in, you can either alter it or simply press Enter again to rerun the same command. The majority of this book will be devoted to explaining and describing the various commands that you will need to use to perform quantitative analyses.
There also are several icons at the top of the screen. The purpose and use of these icons are covered throughout the book. Each of these basic windows will become familiar to you as we go through this book. For now, be sure that you feel comfortable identifying the main purpose of each of the windows.
Getting Started With Data Files
When working with Stata, you will be using what is referred to as a “data file.” If you are familiar with typical database programs, then you already know what a data file basically is. These files contain information (often numerical) on a set of cases, such as respondents to a survey, a sample of schools, or each of the states in the United States. Generally, data files are organized such that information regarding each case is contained in one row in the file, whereas each column represents a variable (i.e., information about that case), such as a person’s gender, a school’s total number of students, or a state’s total square miles.
Similar to most computer files, data files come in many different types. But just as a PDF (portable document format) file is very similar to a word document, so too are all data files essential derivations of a similar structure. Each of these derivations is denoted by a different file extension—the letters that come after the “ . ” in a file name. The primary file for Stata data files is .dta. Moving other types of data files into Stata (e.g., Microsoft Excel files) is covered in the Using Different Types of Data Files in Stata section of this chapter.
Opening and Saving Stata Data Files
To open a data file that is in Stata format (i.e., one that has a .dta extension), select the File menu (in the upper left-hand corner) and then choose Open. Or alternatively, you can simply click on the
FIGURE 1.2 • STATA DISPLAY WITH DATA OPEN
The first operation you performed is now displayed in both the Results and Review windows. Again, whenever we tell Stata to “do” something, whether through the point-and-click menus or by entering a command in the Command window, it will be displayed in the Results and Review windows. Because opening a data file does not have any “results,” only the command is displayed in the Results window. You can also see that the data file contains five variables, listed in the Variables window. All the information provided about each variable in this window is discussed in a later section, but for now, the most important aspect is the variable name. In this data set, the five variables are named ids, gender, agecats, employst, and religoth. These variable names should give you some indication of what type of information the variable contains. The variable