Gretl User's Guide
Total Page:16
File Type:pdf, Size:1020Kb
Gretl User’s Guide Gnu Regression, Econometrics and Time-series Allin Cottrell Department of Economics Wake Forest university Riccardo “Jack” Lucchetti Dipartimento di Economia Università Politecnica delle Marche December, 2008 Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation (see http://www.gnu.org/licenses/fdl.html). Contents 1 Introduction 1 1.1 Features at a glance ......................................... 1 1.2 Acknowledgements ......................................... 1 1.3 Installing the programs ....................................... 2 I Running the program 4 2 Getting started 5 2.1 Let’s run a regression ........................................ 5 2.2 Estimation output .......................................... 7 2.3 The main window menus ...................................... 8 2.4 Keyboard shortcuts ......................................... 11 2.5 The gretl toolbar ........................................... 11 3 Modes of working 13 3.1 Command scripts ........................................... 13 3.2 Saving script objects ......................................... 15 3.3 The gretl console ........................................... 15 3.4 The Session concept ......................................... 16 4 Data files 19 4.1 Native format ............................................. 19 4.2 Other data file formats ....................................... 19 4.3 Binary databases ........................................... 19 4.4 Creating a data file from scratch ................................. 20 4.5 Structuring a dataset ......................................... 22 4.6 Missing data values ......................................... 26 4.7 Maximum size of data sets ..................................... 27 4.8 Data file collections ......................................... 27 5 Special functions in genr 30 5.1 Introduction .............................................. 30 5.2 Long-run variance .......................................... 30 5.3 Time-series filters .......................................... 30 5.4 Panel data specifics ......................................... 32 i Contents ii 5.5 Resampling and bootstrapping .................................. 34 5.6 Cumulative densities and p-values ................................ 35 5.7 Handling missing values ...................................... 35 5.8 Retrieving internal variables .................................... 36 5.9 Numerical procedures ........................................ 37 5.10 The discrete Fourier transform .................................. 39 6 Sub-sampling a dataset 43 6.1 Introduction .............................................. 43 6.2 Setting the sample .......................................... 43 6.3 Restricting the sample ........................................ 44 6.4 Random sampling .......................................... 45 6.5 The Sample menu items ....................................... 45 7 Graphs and plots 46 7.1 Gnuplot graphs ............................................ 46 7.2 Boxplots ................................................ 47 8 Discrete variables 49 8.1 Declaring variables as discrete ................................... 49 8.2 Commands for discrete variables ................................. 50 9 Loop constructs 54 9.1 Introduction .............................................. 54 9.2 Loop control variants ........................................ 54 9.3 Progressive mode ........................................... 57 9.4 Loop examples ............................................ 58 10 User-defined functions 62 10.1 Defining a function .......................................... 62 10.2 Calling a function ........................................... 63 10.3 Deleting a function .......................................... 64 10.4 Function programming details ................................... 64 10.5 Function packages .......................................... 70 11 Named lists and strings 75 11.1 Named lists .............................................. 75 11.2 Named strings ............................................. 78 12 Matrix manipulation 82 12.1 Creating matrices ........................................... 82 12.2 Empty matrices ............................................ 83 Contents iii 12.3 Selecting sub-matrices ........................................ 83 12.4 Matrix operators ........................................... 85 12.5 Matrix–scalar operators ....................................... 86 12.6 Matrix functions ........................................... 86 12.7 Matrix accessors ........................................... 93 12.8 Namespace issues .......................................... 94 12.9 Creating a data series from a matrix ............................... 94 12.10Matrices and lists ........................................... 94 12.11Deleting a matrix ........................................... 95 12.12Printing a matrix ........................................... 95 12.13Example: OLS using matrices .................................... 96 13 Cheat sheet 97 13.1 Dataset handling ........................................... 97 13.2 Creating/modifying variables ................................... 98 13.3 Neat tricks ............................................... 99 II Econometric methods 101 14 Robust covariance matrix estimation 102 14.1 Introduction .............................................. 102 14.2 Cross-sectional data and the HCCME ............................... 103 14.3 Time series data and HAC covariance matrices ........................ 104 14.4 Special issues with panel data ................................... 108 15 Panel data 110 15.1 Estimation of panel models .................................... 110 15.2 Dynamic panel models ....................................... 114 15.3 Panel illustration: the Penn World Table ............................. 116 16 Nonlinear least squares 118 16.1 Introduction and examples ..................................... 118 16.2 Initializing the parameters ..................................... 118 16.3 NLS dialog window .......................................... 119 16.4 Analytical and numerical derivatives ............................... 119 16.5 Controlling termination ....................................... 120 16.6 Details on the code .......................................... 120 16.7 Numerical accuracy ......................................... 120 17 Maximum likelihood estimation 123 17.1 Generic ML estimation with gretl ................................. 123 Contents iv 17.2 Gamma estimation .......................................... 125 17.3 Stochastic frontier cost function ................................. 126 17.4 GARCH models ............................................ 127 17.5 Analytical derivatives ........................................ 129 17.6 Debugging ML scripts ........................................ 130 17.7 Using functions ............................................ 131 18 GMM estimation 135 18.1 Introduction and terminology ................................... 135 18.2 OLS as GMM .............................................. 136 18.3 TSLS as GMM ............................................. 138 18.4 Covariance matrix options ..................................... 138 18.5 A real example: the Consumption Based Asset Pricing Model ................ 140 18.6 Caveats ................................................. 142 19 Model selection criteria 144 19.1 Introduction .............................................. 144 19.2 Information criteria ......................................... 144 20 Time series models 146 20.1 Introduction .............................................. 146 20.2 ARIMA models ............................................ 146 20.3 Unit root tests ............................................. 151 20.4 ARCH and GARCH .......................................... 153 21 Cointegration and Vector Error Correction Models 157 21.1 Introduction .............................................. 157 21.2 Vector Error Correction Models as representation of a cointegrated system ....... 158 21.3 Interpretation of the deterministic components ........................ 159 21.4 The Johansen cointegration tests ................................. 161 21.5 Identification of the cointegration vectors ........................... 162 21.6 Over-identifying restrictions .................................... 164 21.7 Numerical solution methods .................................... 170 22 Discrete and censored dependent variables 173 22.1 Logit and probit models ....................................... 173 22.2 Ordered response models ..................................... 176 22.3 Multinomial logit ........................................... 176 22.4 The Tobit model ........................................... 179 22.5 Interval regression .......................................... 179 22.6 Sample selection model ....................................... 180 Contents v 23 Quantile regression 184 23.1 Introduction .............................................. 184 23.2 Basic syntax .............................................. 184 23.3 Confidence intervals ......................................... 185 23.4 Multiple quantiles .......................................... 185 23.5 Large datasets ............................................. 186 III Technical details 188 24 Gretl and TEX 189 24.1 Introduction .............................................