Stata_Manual_2015 - Basic Econometrics with Stata Carl Moody Economics Department College of William and Mary 2014 Table of Contents 1 AN OVERVIEW

Stata_Manual_2015 - Basic Econometrics with Stata Carl...

This preview shows page 1 out of 234 pages.

Unformatted text preview: Basic Econometrics with Stata Carl Moody Economics Department College of William and Mary 2014 Table of Contents 1 AN OVERVIEW OF STATA ......................................................................................... 5 Transforming variables ................................................................................................... 7 Continuing the example .................................................................................................. 9 Reading Stata Output ...................................................................................................... 9 2 STATA LANGUAGE ................................................................................................... 12 Basic Rules of Stata ...................................................................................................... 12 Stata functions ............................................................................................................... 14 Missing values .......................................................................................................... 16 Time series operators. ............................................................................................... 16 Setting panel data. ..................................................................................................... 17 Variable labels. ......................................................................................................... 18 System variables ....................................................................................................... 18 3 DATA MANAGEMENT............................................................................................... 19 Getting your data into Stata .......................................................................................... 19 Using the data editor ................................................................................................. 19 Importing data from Excel ........................................................................................ 19 Importing data from comma separated values (.csv) files ........................................ 20 Reading Stata files: the use command ...................................................................... 22 Saving a Stata data set: the save command ................................................................... 22 Combining Stata data sets: the Append and Merge commands .................................... 22 Looking at your data: list, describe, summarize, and tabulate commands ................... 24 Culling your data: the keep and drop commands.......................................................... 27 Transforming your data: the generate and replace commands ..................................... 27 4 GRAPHS ........................................................................................................................ 29 5 USING DO-FILES......................................................................................................... 34 6 USING STATA HELP .................................................................................................. 37 7 REGRESSION ............................................................................................................... 41 Linear regression ........................................................................................................... 43 Correlation and regression ............................................................................................ 46 How well does the line fit the data? .......................................................................... 48 Why is it called regression? .......................................................................................... 49 The regression fallacy ................................................................................................... 51 Horace Secrist ........................................................................................................... 53 Some tools of the trade ................................................................................................. 54 Expected value .......................................................................................................... 55 Expected values, means and variance ....................................................................... 56 8 THEORY OF LEAST SQUARES ................................................................................ 57 1 Method of least squares ................................................................................................ 57 Properties of estimators................................................................................................. 58 Small sample properties ............................................................................................ 58 Large sample properties ............................................................................................ 59 Mean of the sampling distribution of βˆ ................................................................... 63 Variance of βˆ ............................................................................................................ 63 Consistency of OLS .................................................................................................. 64 Proof of the Gauss-Markov Theorem ........................................................................... 65 Inference and hypothesis testing ................................................................................... 66 Normal, Student’s t, Fisher’s F, and Chi-square ....................................................... 66 Normal distribution ................................................................................................... 67 Chi-square distribution.............................................................................................. 68 F-distribution............................................................................................................. 70 t-distribution.............................................................................................................. 71 Asymptotic properties ................................................................................................... 73 Testing hypotheses concerning β .................................................................................. 73 Degrees of Freedom ...................................................................................................... 74 Estimating the variance of the error term ..................................................................... 75 Chebyshev’s Inequality................................................................................................. 78 Law of Large Numbers ................................................................................................. 79 Central Limit Theorem ................................................................................................. 80 Method of maximum likelihood ................................................................................... 84 Likelihood ratio test .................................................................................................. 86 Multiple regression and instrumental variables ............................................................ 87 Interpreting the multiple regression coefficient. ....................................................... 90 Multiple regression and omitted variable bias .............................................................. 92 The omitted variable theorem ....................................................................................... 93 Target and control variables: how many regressors?.................................................... 96 Proxy variables.............................................................................................................. 97 Dummy variables .......................................................................................................... 98 Useful tests .................................................................................................................. 102 F-test ....................................................................................................................... 102 Chow test ................................................................................................................ 102 Granger causality test ............................................................................................. 105 J-test for non-nested hypotheses ............................................................................. 107 LM test .................................................................................................................... 108 9 REGRESSION DIAGNOSTICS ................................................................................. 111 Influential observations ............................................................................................... 111 DFbetas ................................................................................................................... 113 Multicollinearity ......................................................................................................... 114 Variance inflation factors ........................................................................................ 114 10 HETEROSKEDASTICITY ....................................................................................... 117 Testing for heteroskedasticity ..................................................................................... 117 Breusch-Pagan test .................................................................................................. 117 White test ................................................................................................................ 120 2 Weighted least squares ................................................................................................ 120 Robust standard errors and t-ratios ............................................................................. 123 11 ERRORS IN VARIABLES ....................................................................................... 127 Cure for errors in variables ......................................................................................... 128 Two stage least squares ............................................................................................... 129 Hausman-Wu test ........................................................................................................ 129 12 SIMULTANEOUS EQUATIONS............................................................................. 132 Example: supply and demand ..................................................................................... 133 Indirect least squares ................................................................................................... 135 The identification problem .......................................................................................... 136 Illustrative example..................................................................................................... 137 Diagnostic tests ........................................................................................................... 140 Tests for over identifying restrictions ..................................................................... 140 Test for weak instruments ....................................................................................... 143 Hausman-Wu test .................................................................................................... 144 Seemingly unrelated regressions................................................................................. 148 Three stage least squares ............................................................................................. 149 Types of equation systems .......................................................................................... 150 Strategies for dealing with simultaneous equations .................................................... 151 Another example ......................................................................................................... 152 Summary ..................................................................................................................... 155 13 TIME SERIES MODELS .......................................................................................... 157 Linear dynamic models ............................................................................................... 157 ADL model ............................................................................................................. 157 Lag operator ............................................................................................................ 158 Static model ............................................................................................................ 159 AR model ................................................................................................................ 159 Random walk model ............................................................................................... 159 First difference model ............................................................................................. 159 Distributed lag model .............................................................................................. 160 Partial adjustment model......................................................................................... 160 Error correction model ............................................................................................ 160 Cochrane-Orcutt model ........................................................................................... 161 14 AUTOCORRELATION ............................................................................................ 162 Effect of autocorrelation on OLS estimates ................................................................ 163 Testing for autocorrelation .......................................................................................... 165 The Durbin Watson test .......................................................................................... 165 The LM test for autocorrelation .............................................................................. 167 Testing for higher order autocorrelation ................................................................. 168 Cumby-Huizinga test for autocorrelation ............................................................... 169 The test is identical to the BG test for lags up to 4. However, when we test the lags individually, the test indicates first order serial correlation only. This is one reason to prefer the CH test over BG. Another reason is that it can be made robust to heteroskedasticity. (See below.) ................................................................................. 170 Cure for autocorrelation .............................................................................................. 170 The Cochrane-Orcutt method ................................................................................. 170 3 Curing autocorrelation with lags ............................................................................. 173 Heteroskedastic and autocorrelation consistent standard errors ................................. 174 Summary ..................................................................................................................... 175 15 NONSTATIONARITY, UNIT ROOTS, AND RANDOM WALKS ....................... 176 Random walks and ordinary least squares .................................................................. 177 Testing for unit roots ................................................................................................... 178 Choosing the number of lags with F tests ............................................................... 181 Digression: model selection criteria........................................................................ 183 Choosing lags using model selection criteria.......................................................... 184 Trend stationarity vs. difference stationarity .............................................................. 185 Why unit root tests have nonstandard distributions .................................................... 186 16 ANALYSIS OF NONSTATIONARY DATA .......................................................... 189 Cointegration............................................................................................................... 192 Dynamic ordinary least squares .................................................................................. 194 Error correction model ................................................................................................ 195 17 PANEL DATA MODELS ......................................................................................... 197 The Fixed Effects Model ............................................................................................ 197 Time series issues ....................................................................................................... 206 Linear trends ........................................................................................................... 206 Nonstationarity, unit roots and panel data .............................................................. 210 Testing for autocorrelation in fixed effects models .................................................... 217 Clustering .................................................................................................................... 219 A problem with clustering in panel fixed effects models ........................................... 221 Cointegration in panel data models............................................................................. 221 Estimating the cointegrating relationship ................................................................... 223 Other Panel Data Models ............................................................................................ 226 Digression: the between estimator .......................................................................... 226 The Random Effects Model .................................................................................... 226 Choosing between the Random Effects Model and the Fixed Effects Model. ....... 227 The Hausman-Wu test again ................................................................................... 228 The Random Coefficients Model. ........................................................................... 228 Index ............................................................................................................................... 230 4 1 AN OVERVIEW OF STATA Stata is a computer program that allows the user to perform a wide variety of statistical analyses. In this chapter we will take a short tour of Stata to get an appreciation of what it can do. Starting Stata Stata is available on the server. When invoked, the screen should look something like this. (This is the current version on my computer. The version on the server may be different.) There are many ways to do things in Stata. The simplest way is to enter commands interactively, allowing Stata to execute each command immediately. The commands are entered in the “Stata Command” window (along the bottom in this view). Results are shown on the right. After the command has been entered it appears in the “Review” window in the upper left. If you want to re-enter the command you can double click on it. A single click moves it to the command line, where you can edit it before submitting. You can also use the buttons on the toolbar at the t...
View Full Document

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture