Using Stata for Quantitative Analysis. Kyle C. Longest

Using Stata for Quantitative Analysis - Kyle C. Longest


Скачать книгу
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.

      4This “copy and paste” method may seem to be the easiest way to transfer data from Microsoft Excel into a Stata format, especially for novice users. But there are some disadvantages to this strategy. More practiced users should transform Excel worksheets into .csv files and then implement the -insheet- command. The specifics of this command are beyond the scope of this introductory text, but the Stata Help Files section of Chapter 8 provides information on how Stata’s Help files can be used to learn how to use this command.

      jpg A CLOSER LOOK: COMBINING DATA

      Often when you are conducting analyses, you will need to expand your data set. Typically, this type of expansion involves one of two possibilities: (1) adding new cases to the data; or (2) adding new variables connected to existing cases. Combining data in either of these situations is not terribly complicated in Stata, but it is rather data-situation specific. Therefore, rather than fully covering the Stata commands to accomplish these tasks in detail, here I provide a general overview of when and why you might need to combine data in these ways, as well as noting the Stata command that allows you to do so. Because completing these types of data combinations is somewhat more advanced, I would encourage readers who realize they may need these commands to work their way through the book so that they feel comfortable with Stata. Then return to this section and combine it with the information in the Stata Help Files section of Chapter 8 to guide yourself through the exact command you will need for your particular data combination goals.

      To fully understand the different types of data combinations that are possible, it may be helpful to use an example. Consider the data you have been working with so far in this chapter as your “original” data that may have come from a survey you conducted. Figure 1.7 presents


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