Using Stata for Quantitative Analysis. Kyle C. Longest

Чтение книги онлайн.

Читать онлайн книгу Using Stata for Quantitative Analysis - Kyle C. Longest страница 4

Автор:
Серия:
Издательство:
Using Stata for Quantitative Analysis - Kyle C. Longest

Скачать книгу

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 jpg icon. From here, you will need to search through the disk drives and folders on your computer to find your saved data file. Note that only files that are saved as .dta files will appear when searching from within Stata. This chapter uses the data file available at study.sagepub.com/longest3e named Chapter 1 Data.dta. Once you have found your data file, double-click the file. Having done this, you will notice that the Stata screen looks different from how it did initially (Figure 1.2).

jpg

      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 gender, for example, says whether each respondent is a male or a female.

      It is a good practice to always save a copy of your data files and only work with the duplicated version. When working with and analyzing data, you often will be forced to change aspects of the data files. For example, you may need to create a new variable or change something about an existing variable. But it is important to have an original version of the data, just in case something undesired occurs. Don’t worry too much; most alterations you perform can be undone or recovered. Working with a duplicate copy of the data is simply an added protection.

      To save a duplicate copy of the data file you have just opened, open the File menu and click on Save As. You can then enter a new file name, such as Chapter 1 Data mycopy.dta, and click Save. This is the procedure you will use whenever you want to save a new version of your data file.

      Data Browser and Editor

      If this is the first time you are working with data, it may be helpful to actually “see” the data. Even if you have experience using data, it may often be helpful to look at the data you are examining. To see the data file in Stata, you can click on the Data Browser icon, jpg, in the middle of the top of the screen. When you do so, you will see a new window that appears as shown in Figure 1.3.

jpg

      FIGURE 1.3 • DATA BROWSER WINDOW

      jpg A CLOSER LOOK: STATA DATA FILES ACROSS VERSIONS

      As was noted in the Preface, the vast majority of Stata features and commands are similar across versions (e.g., Stata 15, 14, 13, etc.). This is true of Stata data files by and large. All Stata data files that are created and/or saved in an older version can be read by a newer version (i.e., they are forward compatible). This means that if you are using Stata 15 but are working with colleagues who are using Stata 14, any files they send to you will open without a problem.

      During certain upgrades, however, Stata data files cease to be “backward” compatible, meaning files saved in a newer version cannot be opened by older versions. Stata 13 happened to be one of those upgrades. If you are using Stata 15 and send a data set that you saved in Stata 15 to your colleagues who are using Stata 13 (or earlier), they will not be able to open it. (Note: This is not a problem if you are moving files between Stata 15 and Stata 14, as these two versions are completely compatible with each other.)

      Do not despair. Stata has built in a very simple feature to overcome this problem. If you know that you want the data you are using in Stata 15 to be opened by older versions, you need to take one extra step (from the process just explained).

      First, click on the File menu and then click on Save As. Now, use the drop-down menu in the Save as Type box and select the Stata 13 Data (*.dta) option or the Stata 12/11 Data (*.dta) (if your colleague happens to be using a version prior to Stata 13). Note that you do not need to change the file extension; it is still .dta. Once you have named your file, click Save. You will know that you have saved the data correctly when the output in the Results window starts with .saveold, which is telling you that the file has been saved in a way that makes it readable by the previous versions. Again, note that when you save a file in this way, it can still be used in Stata 15.

      This new window, as is denoted in its upper left-hand corner, is the Data Editor (Browse) window. The “(Browse)” aspect indicates that you are only looking at the data, not actually changing them.

      In this window, you see all five of the variables that were listed in the Variables window. As was mentioned earlier, each row is a different case (i.e., a National Study of Youth and Religion [NSYR] respondent), and each column is a different variable. Each cell then contains information on the given variable for that case. For example, the case in the first row is a “Male” respondent who mentioned that “Mormon” was his other religion. To close this window, click on the red “X” in the upper right-hand corner.

      There may be times when you would want to change the value of a particular case on an individual variable. One way to do so is by using the Data Editor window. (A more efficient way to change the values of multiple cases is covered in The 5 Essential Commands: replace (if) section of Chapter 2.) To begin, click on the Data Editor icon, jpg, which is next to the Data Browser icon. You may notice that the Data Editor and Data Browser windows look very similar. The main difference is that in the upper left-hand corner of the window, after “Data Editor,” the window now reads “(Edit).” It is important to know which window you have opened because you can change the values of the data when the Editor is open. To prevent any accidental alterations, it is generally advised only to use the Data Browser window, unless you are certain you want to change a particular value.

      After you have opened the Data Editor window, use the direction keys (or mouse) to highlight the cell you would like to change. For example, you may have realized that the first case’s age was incorrectly entered in the data file. Instead of being 23 years old, this case should only be 22 years old. To make this change, once you have the cell in the first row listed under agecats highlighted, type 22 and press Enter. This case’s value for the variable agecats has now changed. When you close the Data Editor window, this operation has been recorded and displayed in both the Review and Results windows.

      

Скачать книгу