Applied Econometrics using MATLAB James P. LeSage Department of Economics University of Toledo October, 1999
1 Introduction 1 2 Regression using MATLAB 5 2.1 Design of the regression library . . . . . . . . . . . . . . . . . 6 2.2 The ols function . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.3 Selecting a least-squares algorithm . . . . . . . . . . . . . . . 12 2.4 Using the results structure . . . . . . . . . . . . . . . . . . . . 17 2.5 Performance pro¯ling the regression toolbox . . . . . . . . . . 28 2.6 Using the regression library . . . . . . . . . . . . . . . . . . . 30 2.6.1 A Monte Carlo experiment . . . . . . . . . . . . . . . 31 2.6.2 Dealing with serial correlation . . . . . . . . . . . . . 32 2.6.3 Implementing statistical tests . . . . . . . . . . . . . . 38 2.7 Chapter summary . . . . . . . . . . . . . . . . . . . . . . . . 41 Chapter 2 Appendix 42 3 Utility Functions 45 3.1 Calendar function utilities . . . . . . . . . . . . . . . . . . . . 45 3.2 Printing and plotting matrices . . . . . . . . . . . . . . . . . 49 3.3 Data transformation utilities . . . . . . . . . . . . . . . . . . 65 3.4 Gauss functions . . . . . . . . . . . . . . . . . . . . . . . . . . 69 3.5 Wrapper functions . . . . . . . . . . . . . . . . . . . . . . . . 73 3.6 Chapter summary . . . . . . . . . . . . . . . . . . . . . . . . 76 Chapter 3 Appendix 77 4 Regression Diagnostics 80 4.1 Collinearity diagnostics and procedures . . . . . . . . . . . . 80 4.2 Outlier diagnostics and procedures . . . . . . . . . . . . . . . 94 4.3 Chapter summary . . . . . . . . . . . . . . . . . . . . . . . .100
Chapter 4 Appendix 101 5 VAR and Error Correction Models 103 5.1 VAR models . . . . . . . . . . . . . . . . . . . . . . . . . . . .103 5.2 Error correction models . . . . . . . . . . . . . . . . . . . . .113 5.3 Bayesian variants . . . . . . . . . . . . . . . . . . . . . . . . .125 5.3.1 Theil-Goldberger estimation of these models . . . . .138 5.4 Forecasting the models . . . . . . . . . . . . . . . . . . . . . .139 5.5 Chapter summary . . . . . . . . . . . . . . . . . . . . . . . .145 Chapter 5 Appendix 148 6 Markov Chain Monte Carlo Models 151 6.1 The Bayesian Regression Model . . . . . . . . . . . . . . . . .154 6.2 The Gibbs Sampler . . . . . . . . . . . . . . . . . . . . . . . .156 6.2.1 Monitoring convergence of the sampler . . . . . . . . .159 6.2.2 Autocorrelation estimates . . . . . . . . . . . . . . . .163 6.2.3 Raftery-Lewis diagnostics . . . . . . . . . . . . . . . .163 6.2.4 Geweke diagnostics . . . . . . . . . . . . . . . . . . . .165 6.3 A heteroscedastic linear model . . . . . . . . . . . . . . . . .169 6.4 Gibbs sampling functions . . . . . . . . . . . . . . . . . . . .175 6.5 Metropolis sampling . . . . . . . . . . . . . . . . . . . . . . .184 6.6 Functions in the Gibbs sampling library . . . . . . . . . . . .190 6.7 Chapter summary . . . . . . . . . . . . . . . . . . . . . . . .197 Chapter 6 Appendix 199 7 Limited Dependent Variable Models 204 7.1 Logit and probit regressions . . . . . . . . . . . . . . . . . . .206 7.2 Gibbs sampling logit/probit models . . . . . . . . . . . . . . .211 7.2.1 The probit g function . . . . . . . . . . . . . . . . . .218 7.3 Tobit models . . . . . . . . . . . . . . . . . . . . . . . . . . .220 7.4 Gibbs sampling Tobit models . . . . . . . . . . . . . . . . . .224 7.5 Chapter summary . . . . . . . . . . . . . . . . . . . . . . . .227 Chapter 7 Appendix 228 8 Simultaneous Equation Models 230 8.1 Two-stage least-squares models . . . . . . . . . . . . . . . . .230 8.2 Three-stage least-squares models . . . . . . . . . . . . . . . .235 8.3 Seemingly unrelated regression models . . . . . . . . . . . . .240
8.4 Chapter summary . . . . . . . . . . . . . . . . . . . . . . . .244 Chapter 8 Appendix 246 9 Distribution functions library 247 9.1 The pdf, cdf, inv and rnd functions . . . . . . . . . . . . . . .248 9.2 The specialized functions . . . . . . . . . . . . . . . . . . . .249 9.3 Chapter summary . . . . . . . . . . . . . . . . . . . . . . . .256 Chapter 9 Appendix 257 10 Optimization functions library 260 10.1 Simplex optimization . . . . . . . . . . . . . . . . . . . . . . .261 10.1.1 Univariate simplex optimization . . . . . . . . . . . .261 10.1.2 Multivariate simplex optimization . . . . . . . . . . .268 10.2 EM algorithms for optimization . . . . . . . . . . . . . . . . .269 10.3 Multivariate gradient optimization . . . . . . . . . . . . . . .278 10.4 Chapter summary . . . . . . . . . . . . . . . . . . . . . . . .287 Chapter 10 Appendix 288 11 Handling sparse matrices 289 11.1 Computational savings with sparse matrices . . . . . . . . . .289 11.2 Estimation using sparse matrix algorithms . . . . . . . . . . .297 11.3 Gibbs sampling and sparse matrices . . . . . . . . . . . . . .304 11.4 Chapter summary . . . . . . . . . . . . . . . . . . . . . . . .309 Chapter 11 Appendix 310 References 313 Appendix: Toolbox functions 320