Example: confidence

An Introduction to Matlab for Econometrics

An Introduction to Matlab for Econometrics John C. Frain TEP Working Paper No. 0110 February 2010 Trinity Economics Papers Department of Economics Trinity College Dublin An Introduction to Matlab for EconometricsJohn C. Frain. February 2010 AbstractThis paper is an Introduction to Matlab for Econometrics . Itdescribes theMATLAB Desktop, contains a sample Matlab session showing elementary MAT-LAB operations, gives details of data input/output, decision and loop structures,elementary plots, describes the LeSage Econometrics toolbox and maximum likeli-hood using the LeSage toolbox. Various worked examples of the use of MATLABin Econometrics are also given. After reading this documentthe reader should beable to make better use of the Matlab on-line help and Preliminaries .. The Matlab Desktop .. The Command Window .. The Command History Window .. The Start Button .. The Edit Debug window .. The Figure Windows .. The Workspace Browser.

AnIntroductiontoMATLABforEconometrics JohnC.Frain. ∗ February2010 Abstract This paper is an introduction to MATLAB for econometrics. It describes the

Tags:

  Introduction, Econometrics, Matlab, Introduction to matlab for econometrics

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of An Introduction to Matlab for Econometrics

1 An Introduction to Matlab for Econometrics John C. Frain TEP Working Paper No. 0110 February 2010 Trinity Economics Papers Department of Economics Trinity College Dublin An Introduction to Matlab for EconometricsJohn C. Frain. February 2010 AbstractThis paper is an Introduction to Matlab for Econometrics . Itdescribes theMATLAB Desktop, contains a sample Matlab session showing elementary MAT-LAB operations, gives details of data input/output, decision and loop structures,elementary plots, describes the LeSage Econometrics toolbox and maximum likeli-hood using the LeSage toolbox. Various worked examples of the use of MATLABin Econometrics are also given. After reading this documentthe reader should beable to make better use of the Matlab on-line help and Preliminaries .. The Matlab Desktop .. The Command Window .. The Command History Window .. The Start Button .. The Edit Debug window .. The Figure Windows .. The Workspace Browser.

2 The Help Browser .. The Path Browser .. Miscellaneous Commands .. 11 Comments are welcome. My email address isfrainj at Vectors, Matrices and A Sample Matlab session .. Entering Matrices .. Basic Matrix operations .. Kronecker Product .. Examples of number formats .. fprintf function .. element by element operations .. miscellaneous functions .. sequences .. Creating Special Matrices .. Random number generators .. Extracting parts of a matrix, Joining matrices together to get anew larger matrix .. Using sub-matrices on left hand side of assignment .. Stacking Matrices .. Special Values .. Examples .. Regression Example .. Simulation Sample Size and OLS Estimates .. Example Macroeconomic Simulation with Matlab .. 343 Data Native Matlab data files .. Importing from Excel .. Reading from text files .. Exporting data to EXCEL, STATA and other programs .. Stat/Transfer.

3 Formatted Output .. Producing material for inclusion in a paper .. 424 Decision and Loop Elementary Plots4626 Systems of Regresssion Using Matlab to estimate systems of regression equations .. Exercise Using Matlab to estimate a simultaneous equation systems .. 597 User written functions in MATLAB598 The LeSage Econometric Toolbox619 Maximum Likelihood Estimation using Numerical Techniques8210 Octave, Scilab and Octave .. Scilab .. R .. 87A Functions etc. in LeSage Econometrics Regression .. Programs .. Demonstrations .. Support functions .. Utilities .. Utility Function Library .. demonstration programs .. Graphing Function Library .. graphing programs .. Demonstration Programs .. Support Functions .. Regression Diagnostics Library .. regression diagnostic programs .. Demonstration Programs .. support functions .. vector autoregressive function library .. VAR/BVAR functions.

4 Demonstration Programs .. Demonstration Programs - continued .. Support Functions .. Co-integration Library .. Co-integration testing routines .. Demonstration Programs .. Support functions .. Gibbs sampling convergence diagnostics functions .. Convergence testing functions .. Demonstration Programs .. Support Functions .. Distribution functions library .. pdf, cdf, inverse functions .. Random Samples .. Demonstration and Test programs .. Support Functions .. Optimization functions library .. Optimization Functions .. Demonstration Programs .. Support Functions .. Spatial Econometrics .. Functions .. Demonstration Programs .. Support Functions .. 1051 PreliminariesThese notes are a guide for students of Econometrics who wishto learn Matlab in MSWindows. I define the functions of Matlab using simple examples. To get the bestbenefit from these notes you should read them sitting in frontof a computer enteringthe various Matlab instructions as you read the notes.

5 The material in the first threesections is elementary and will be required by all economists starting with remaining sections contain some more advanced materialand should be read these notes I have used a mono-spaced font for Matlab instructions and for com-puter input and output. Descriptive material, explanations and commentary on thecomputer input/output is given in the current the first aim of these notes is to get the reader started in the use of MATLABfor Econometrics it should be pointed out that Matlab has many uses in recent years it has been used widely in what has become known as computationaleconomics. This area has applications in macroeconomics, determination of optimalpolicies and in finance. Recent references include Kendricket al. (2006), Marimon andScott (1999), Miranda and Fackler (2002) and Ljungqvist andSargent (2004).I do not know of any book on Matlab written specifically for economics. Creel (2008)is a set of lecture notes on Econometrics which can be downloaded from the web.

6 Thiscontains examples of quantitative econometric analysis using GNU Octave which hasa syntax similar to Matlab (see section ). LeSage (1999)is a free econometricstoolbox available for download Thissite also contains links to several other Matlab resources useful in Econometrics . Afree ARCH/GARCH toolbox is available athttp:// MathWorks, the composers of Matlab have a list of books usingMATLAB for Economics/Finance ( ). They have also issued anew Econometrics toolbox ( ).The MathWorks overview of this toolbox indicates that is is targeted at econometric timeseries in finance. For advanced applications in applied probability Paolella (2006, 2007)are comprehensive accounts of computational aspects of probability theory using MAT-LAB. Higham and Higham (2005) is a good book on Matlab intended for all users ofMATLAB. Pratap (2006) is a good general getting started book. There are also manyexcellent books covering Matlab for Engineers and/or Scientists which you might finduseful if you need to use Matlab in greater notes can not give a comprehensive account of Matlab .

7 Your copy of Matlab comes with one of the best on-line help systems available. Full versions of the manualsare available in portable document format on the web started life, in the late 70 s, as a computer program for handling matrixoperations. Over the years it has been extended and the basicversion of MATLABnow contains more than 1000 functions. Various toolboxes have also been writtento add specialist functions to Matlab . Anyone can extend Matlab by adding theirown functions and/or toolboxes. Any glance at an Econometrics textbook shows thateconometrics involves much matrix manipulation and Matlab provides an excellentplatform for implementing the various textbook proceduresand other state of the artestimators. Before you use Matlab to implement procedures from your textbook youmust understand the matrix manipulations that are involvedin the procedure. Whenyou implement them you will understand the procedure better. Using a black boxpackage may, in some cases, be easier but how often do you knowexactly what the blackbox is producing.

8 Using Matlab for Econometrics may appear to involve a lot of extrawork but many students have found that it helps their understanding of both matrixtheory and Matlab as it all other packages it makes life much easier ifyou organise your work5properly. The procedure That I use is some variation of the following 1. Set up a new directory for each project ( :\ Matlab \project1)2. Set up a shortcut for each project. The shortcut should specify that the programstart in the data directory for the project. If all your work is on the same PC theshortcut is best stored on the desktop. If you are working on aPC in a computerlab you will not be able to use the desktop properly and the shortcut may bestored in the directory that you have set up for the project. If you have severalprojects in hand you should set up separate shortcuts and directories for each ofthem. Each shortcut should be renamed so that you can associate it with therelevant Before starting Matlab you are strongly advised to amend the options in Win-dows explorer so that full filenames (including any file extensions allocated toprograms) appear in Windows Explorer and any other Windows file access The Matlab DesktopThe Matlab desktop has the following parts -1.

9 The Command Window2. The Command History Window3. The Start Button4. The Documents Window (including the Editor/(Debugger) and Array Editor5. The Figure Windows6. The Workspace Browser7. The Help Browser8. The Path The Command WindowThe simplest use of the command window is as a calculator. With a little practice itmay be as easy, if not easier, to use than a spreadsheet. Most calculations are enteredalmost exactly as one would write them.>> 2+2ans = 4>> 3*2ans = 66 The objectanscontains the result of the last calculation of this kind. Youmay alsocreate an objectawhich can hold the result of your calculation.>> a=3^3a = 27>> aa = 27>> b=4^2+1b = 17>> b=4^2+1;% continuation lines>> 3+3 ..+3ans = 9 Type each instruction in the command window, press enter andwatch the answer. Note The arithmetic symbols+, -, *, /and^have their usual meanings The assignment operator= the Matlab command prompt>> A;at the end of a command does not produce output but the assignment is madeor the command is completed If a statement will not fit on one line and you wish to continue it to a second typean ellipsis (.))

10 At the end of the line to be instructions can be gathered together in an m-file and may be run togetherfrom that file (or script). An example of a simple m-file is given in the description of theEdit Debug window below. You may extend Matlab by composing new Matlab instructions using existing instructions gathered together in a script may use the up down arrow keys to recall previous commands(from the current orearlier sessions) to the Command Window. You may the edit therecalled command be-fore running it. Further access to previous commands is available through the The Command History WindowIf you now look at the Command History Window you will see thatas each command wasentered it was copied to the Command History Window. This contains all commands7previously issued unless they are specifically deleted. To execute any command in thecommand history double click it with the left mouse button. To delete a commandsfrom the history select them, right click the selection and select delete from the dropdown The Start ButtonThis allows one to access various Matlab functions and worksin a manner similar tothe Start button in The Edit Debug windowClearly Matlab would not be of much use if one was required, every time you usedMATLAB, to enter your commands one by one in the Command Window.


Related search queries