Using Gretl for Principles of Econometrics, 4Th Edition Version 1.0411
Total Page:16
File Type:pdf, Size:1020Kb
Using gretl for Principles of Econometrics, 4th Edition Version 1.0411 Lee C. Adkins Professor of Economics Oklahoma State University April 7, 2014 1Visit http://www.LearnEconometrics.com/gretl.html for the latest version of this book. Also, check the errata (page 459) for changes since the last update. License Using gretl for Principles of Econometrics, 4th edition. Copyright c 2011 Lee C. Adkins. 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 AppendixF for details). i Preface The previous edition of this manual was about using the software package called gretl to do various econometric tasks required in a typical two course undergraduate or masters level econo- metrics sequence. This version tries to do the same, but several enhancements have been made that will interest those teaching more advanced courses. I have come to appreciate the power and usefulness of gretl's powerful scripting language, now called hansl. Hansl is powerful enough to do some serious computing, but simple enough for novices to learn. In this version of the book, you will find more information about writing functions and using loops to obtain basic results. The programs have been generalized in many instances so that they could be adapted for other uses if desired. As I learn more about hansl specifically and programming in general, I will no doubt revise some of the code contained here. Stay tuned for further developments. As with the last edition, the book is written specifically to be used with a particular textbook, Principles of Econometrics, 4th edition (POE4 ) by Hill, Griffiths, and Lim. It could be used with many other introductory texts. The data for all of the examples used herein are available as a package from my website at http://www.learneconometrics.com/gretl.html. If you are unfamiliar with gretl and are interested in using it in class, Mixon Jr. and Smith(2006) and Adkins(2011 a) have written a brief review of gretl and how it can be used in an undergraduate course that you may persuade you to give it a try. The chapters are arranged in the order that they appear in Principles of Econometrics. Each chapter contains a brief description of the basic models to be estimated and then gives you the specific instructions or gretl code to reproduce (nearly) all of the examples in the book. Where appropriate, I've added a bit of pedagogical material that complements what you'll find in the text. I've tried to keep this to a minimum since this is not supposed to serve as a substitute for your text book. The best part about this manual is that it, like gretl, is free. It is being distributed in Adobe's pdf format and I will make corrections to the text as I find errors. Gretl's ability to process user written functions greatly expands the usefulness of the appli- cation. In several of the chapters functions are used to estimate models, select models, and to compute various statistics. The scripting language, continues to evolve in useful ways, becoming more transparent in use and more functional. Though not explored in this book, the ability to ii give function writers access to the basic GUI and to package things into bundles is s very exciting development. Functions can be shared and imported easily through gretl, especially if you are connected to the internet. If gretl doesn't do what you want it to now, stay tuned. It soon may. If recent activity is any indication, I am confident that the the gretl team will continue to improve this already very useful application. I hope that this manual is similarly useful to those using Principles of Econometrics. There are some significant changes in the 4th edition of POE and that means there are some changes in this book from the previous edition. As in the previous edition of this e-book, I have attempted to provide gretl instructions for each and every example in the book. My solutions are not necessarily the most elegant. In some cases elegance gives way to simplicity of programming, especially with respect to the types of students who are likely to be using this book. I have made an effort to generalize some of the script so that it will be easier to adapt to new needs. I've also made liberal uses of loops and functions. These are powerful tools and a thorough understanding of them can take your gretl and econometric skills to the next level. Feel free to send suggestions. Another change in this version of the book is that I've made some effort to generalize some of the scripts. Although that should make it easier to generalize them to a new use, it does mean that they have become a little more complicated. A heavy reliance on user written functions is evident. I invite users to take the time to work through these in order to advance your programming and econometric skills. To make things easier to find in the book, I have added an index. In the pdf, you can click on the page number listed in the index and be taken to the relevant spot in the text. Also, the figure numbers, equation numbers, and citations are also `hot' and can be used in this fashion as well. Since some may prefer to print the manual out rather than work from the .pdf, I opted to make the `hot' links black in color, which disguises their functionality. Finally, I want to say that my conversion to gretl was not immediate. In fact I still use other software as occasions require, though more infrequently. That said, I have become a true believer in the power of gretl. It is now my go to software. I trust it. It is simple to use and to program. In my opinion it combines the best of Gauss and Eviews. It is both a high level programming language and a useful front-end for doing standard econometrics. The ease with which one can move back and forth from both uses makes it truly unique. As a former Gauss user, I find gretl up to the tasks that I choose. I heartily recommend that you take some time to work with it and to learn it. You can't help but come to appreciate its power. Its worth is derived from what it does, not its price. I want to thank the gretl team of Allin Cottrell and Riccardo Lucchetti for putting so much effort into gretl. I don't know how they find the time to make this such a worthwhile project. It is a terrific tool for teaching and doing econometrics. It has many capabilities beyond the ones I discuss in this book and other functions are added regularly. Also, Jack has kindly provided me with suggestions and programs that have made this much better than it would have been otherwise. iii Any remaining errors are mine alone. I also want to thank my good friend and colleague Carter Hill for suggesting I write this and Oklahoma State University and our College of Business for continuing to pay me while I work on it. Copyright c 2007, 2008, 2009, 2011 Lee C. Adkins. iv Contents 1 Introduction 1 1.1 What is Gretl?....................................1 1.1.1 Installing Gretl .................................2 1.1.2 Gretl Basics...................................3 1.1.3 Common Conventions..............................5 1.2 Importing Data.....................................6 1.3 Using the gretl Language...............................8 1.3.1 Console......................................8 1.3.2 Scripts....................................... 10 1.3.3 Sessions...................................... 12 1.3.4 Generating New Variables............................ 13 1.4 GNUPLOT....................................... 14 2 Simple Linear Regression 19 2.1 Simple Linear Regression Model........................... 19 2.2 Retrieve the Data................................... 19 v 2.3 Graph the Data.................................... 22 2.4 Estimate the Food Expenditure Relationship.................... 23 2.4.1 Elasticity..................................... 25 2.4.2 Prediction..................................... 26 2.4.3 Estimating Variance............................... 26 2.5 Repeated Sampling.................................. 27 2.6 Estimating Nonlinear Relationships......................... 31 2.7 Regression with an Indicator Variable........................ 33 2.8 Monte Carlo Simulation................................ 34 2.9 Script.......................................... 37 3 Interval Estimation and Hypothesis Testing 45 3.1 Confidence Intervals.................................. 45 3.2 Repeated Sampling.................................. 48 3.3 Monte Carlo Experiment............................... 50 3.4 Hypothesis Tests.................................... 51 3.5 Script for t-values and p-values............................ 55 3.6 Linear Combination of Parameters.......................... 57 3.7 Script.......................................... 59 4 Prediction, Goodness-of-Fit, and Modeling Issues 62 4.1 Prediction in the Food Expenditure Model..................... 62 4.2 Coefficient of Determination............................. 64 4.3 Choosing a Functional Form............................. 67 vi 4.3.1 Linear-Log Specification............................. 68 4.3.2 Residual Plots.................................. 70 4.3.3 Testing for Normality.............................. 72 4.4 Reporting Results................................... 75 4.5 Polynomial Models................................... 77 4.5.1 Wheat Yield................................... 77 4.5.2 Growth Model.................................. 79 4.5.3 Wage Equation.................................. 80 4.5.4 Generalized R2 .................................