Using Stata for Quantitative Analysis. Kyle C. Longest

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

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

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

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

target="_blank" rel="nofollow" href="#fb3_img_img_11e34042-9392-5985-a714-c81a274d5a01.jpg" alt="jpg"/> A CLOSER LOOK: YOUR FIRST COMMAND

      You may have noticed that when you changed the first case’s value using the Data Editor window, the following text was displayed in the Results window:

      replace agecats = 22 in 1

      (1 real change made)

      Whenever you use the menus or a point-and-click method for performing an operation in Stata, it displays in the Results and Review window the command that would be entered in the Command window to perform the same operation. In this Data Editor example, you can see that the command to change a value is -replace-. If you had entered this full command into the Command window and pressed Enter, the same change would have been made. At times, it may be helpful to perform an operation for the first time using the menus, but, as will be discussed in much more detail in Chapter 2, it is extremely beneficial to know and use the commands via the Command window for the majority of the operations you need to perform.

      The rest of this book will discuss how to perform operations using the Command window. But to see the connection between the menu-based operation and the Command window, try this: Type (or copy and paste) the full command (except the first “.”) that was displayed in the Results window when you closed the Data Editor window into the Command window. Now change the “22” to “23.” The command should read

      replace agecats = 23 in 1

      Then press Enter. Open the Data Browser window again and notice the change to the first case’s value under agecats.

      Entering Your Own Data

      Many data files you analyze will already be in Stata format or in a format that can be easily converted to Stata format (more on this topic below). Yet there may be times when you need to enter the data from a study. For example, if you distributed a survey through the mail, you will need to input the responses to each question for each case so that you can analyze them in Stata.

      The first step in entering your own data after you have opened Stata is to open the Data Editor window as above. From here you can simply enter the values for each case on each variable. Entering data in this way is very similar to entering values into a Microsoft Excel file. The Data Editor, however, does not have the equation functionalities that an Excel file would.

      When you begin entering values, each variable is automatically named var1, var2, and so on. Most often, it is helpful to have the variable names be more descriptive of the values they contain. One way to change these generic names to something that more clearly identifies the variable is to click on the current name of the given variable you want to rename (e.g., var1) listed near the top of the Editor window. Doing so will bring up that variable’s information in the Properties window (inside the Data Editor window). Then click on the current variable name listed in the Name blank in that Properties window. From there you can simply delete the current name and enter the desired name. Another option would be to close the Data Editor window when you have finished entering all of the data. Then you can click on the variable name (e.g., var2) in the Variables window, which will bring up that variable’s information in the Properties window. To change the name in this Properties window, you will need to click on the padlock icon in the Properties window. Then you will need to click on the current variable name listed in the Name blank and simply type the new name in the blank.

      Once you have finished entering all your data, close the Data Editor and follow the steps described above to save a copy of your data file in Stata format.

      Using Different Types of Data Files in Stata

      Some data files may not be available in Stata format. Therefore, a few steps are needed to work with these files in Stata. It would be virtually impossible to cover every possible data file type and how each can be transferred to be usable in Stata. Instead, the most common types will be covered. Also note that there are other computer software programs that are specifically designed to convert data files into various formats (e.g., Stat/Transfer). If you have access to such a program, it is probably the most effective and efficient way to transfer files into a Stata format. Some statistical software packages also offer the option of saving a data file in a different format, which often includes the Stata.dta extension.

      One of the most frequently encountered data file types that is not Stata-ready is a Microsoft Excel file. Usually, these files are denoted with the.xls extension, but other extensions (e.g., .csv) that are generated or readable by Microsoft Excel can be treated in a similar fashion.

      4You will also notice that you could select several different data file formats from this window. The general procedure for each of these formats is very similar to the procedures discussed for Excel files but may contain particular steps for specific files.

jpg

      FIGURE 1.4 • IMPORT DATA FROM EXCEL FILE WINDOW

      Click on the Browse button to find the Excel data that you would like to turn into a Stata data set. Once you have selected the Excel file, you can pick a particular worksheet from that file or even a particular set of cells by using the corresponding boxes. Once you have selected a file, you need to make one key determination that is based on how the data are entered in the Excel file. Notice the radio box to denote “Import first row as variable names.” Whether you should select this option will depend on whether your Excel file contains variable names in the first row or whether it contains only data. The two formats are shown in Figures 1.5 and 1.6.

jpg

      FIGURE 1.5 • FIRST ROW AS VARIABLE NAMES

jpg

      FIGURE 1.6 • FIRST ROW AS DATA

      If the first row contains variable names (as shown in Figure 1.5), click the radio button next to Import first row as variable names (when you do this, notice that the data shown in the preview window will change). Then click OK. If the first row contains data (as shown in Figure 1.6), leave this radio button unchecked and click OK. After you have selected the option that fits with the type of data file you have, close the Data Editor and follow the previously described steps to save the data from within Stata as a Stata data file. Once you have saved your data as a Stata data file, you can simply open and use this version of your data.

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