Spatial Econometric Analysis Using GAUSS 2 Kuan-Pin Lin Portland State University
GAUSS Mathematical and Statistical System Windows Interface Windows Command, Error, Log, … Menu File, Edit, Run, …, Help Operation Interactive Mode Command (Input / Output) Batch Mode Writing Program Online Help
GAUSS Basics Basic Operations on Matrices + - ^ .* ./ % ! * / .< .<= .== .>= .> ./= < <= == >= > /= .not .and .or .xor not and or xor ~ | .*. *~ Special Operators [] {} : . '(transpose) Useful Algrbra and Matrix Operations exp ln log abs sqrt pi sin cos inv invpd(inverse) det(determinant) Example Least Squares: b=y/x
GAUSS Programming Useful GAUSS Functions System Functions: use, load, output Data Generating Functions: ones, zeros, eye, seqa, seqm, rndu, rndn Data Conversion Functions: reshape, selif, delif, vec, vech, xpnd, submat, diag, diagrv Basic Matrix Functions: Matrix Description: rows, cols, maxc, minc, meanc, median, stdc Matrix Operations: sumc,cumsumc,prodc,cumprodc,sortc,sorthc,sortind Matrix Computation: det,inv,invpd,solpd,vcx,corrx,cond,rank,eig,eigh Probability and Statistical Functions: pdfn, cdfn, cdftc, cdffc, cdfchic, dstat, ols Calculus Functions: gradp, hessp, intsimp, linsolve, eqsolve, sqpsolve
GAUSS Programming Controlling Execution Flow If Statement if; then; else; elseif; endif; For Loop for i (start,stop,step); ... endfor; Do Loop do while ... endo; do until ... endo;
GAUSS Programming Write Your Own Functions Single Line Function fn fn_name(args) = code_for_function; Procedure proc [[(nrets)=]] proc_name(arg_list); local list of local variables; ... statements in the body of procedure; retp(ret_list); endp;
GAUSS Programming Example 1 Do you know the accuracy of your computer's numerical calculation? This example addresses this important problem. Suppose e is a known small positive number, and the 5x4 matrix X is defined as follows: Verify that the eigenvalues of X'X are 4+e2, e2, e2, and e2. How small of the value of e your computer will allow so that X'X can be inverted? (example.1) one=ones(1,4); e=1.0; do until e < 1.0e-20; x=one|(e.*eye(4)); print "e = " e; r=eigrs(x'x); print r'; invx=invpd(x'x); print invx; e=e/10; endo;
GAUSS Programming Example 2 Write a single-line GAUSS function to convert a quarterly time series into the annual series by taking the average of every four data points. How you extend the single-line version of time series conversion function to a multi-line procedure so that it can handle the conversion of more than one time series? (example.2) fn qtoa1(x) = meanc(reshape(x,rows(x)/4,4)'); proc qtoa(x); local r,c,y,i; r = rows(x); c = cols(x); y = qtoa1(x[.,1]); i = 2; do until i > c; y = y~qtoa1(x[.,i]); i = i+1; endo; retp(y); endp;
GPE2 for GAUSS GPE2 is a package of econometric procedures written in GAUSS. There are four main functions, driven by a set of global control variables: Reset Set up global control (input and output) variables. Estimate Estimation of a linear or generalized linear model. Forecast Forecasting based on a linear or generalized linear model. Optimize Estimation of a nonlinear model. Gpehelp Online help of using GPE2.
GPE2 for GAUSS Selected Global Control Variables Input Control Variables _names, _begin, _end, _rstat, _rtest, _rplot, _rlist,_const, _restr, _vcov, _hacv, _weight, _ivar, _dlags, _pdl, _eq, _id, _ar, _ma, _arma, _garch, _acf, _acf2, _nlopt, _method, _iter, _tol, _step, _conv, _fbrgin, _fend, _fstat, _fplot, _splag, _spw, _spwd Output Control Variables __y, __x, __e, __b, __vb, __v, __rss, __r2, __f, __vf, __t, __a, __va
GPE2 for GAUSS A Typical Program Using GPE2 /* ** Comments on program title, purposes, and the usage of the program */ use gpe2; @ using GPE package (version 2) @ // this must be the first executable statement ** Writing output to file or sending it to printer: ** specify file name for output // Loading data: read data series from data files. ** Generating or transforming data series: ** create and generate variables with data scaling or transformation ** (e.g. y and x are generated here and will be used below) call reset; @ initialize global variables @ ** Set input control variables for model estimation ** (e.g. _names for variable names, see Appendix A) call estimate(y,x); @ do model estimation @ // variables y, x are generated earlier ** Retrieve output control variables for model evaluation and analysis ** Set more input control variables if needed, for model prediction ** (e.g. _b for estimated parameters) call forecast(y,x); @ do model prediction @ end; @ important: don’t forget this @
GPE2 for GAUSS Examples More than 70 examples covering linear and nonlinear least squares, instrumental variables, system of simultaneous linear equations, time series analysis, panel data, limited dependent variables, maximum likelihood, generalized methods of moments, and … The latest extensions include spatial lag model estimation, hypothesis testing, and robust inference.
Software Demonstration Installation GAUSS Light 10.0 GPE2 for GAUSS 10.0 Example: Zellner and Revankar [1970] U.S. Transportation Equipment Industry Cobb-Douglas Production Function ln(Q) = a + b ln(L) + g ln(K) + e Generalized Cobb-Douglas Production Function ln(Q) + q Q = a + b ln(L) + g ln(K) + e
Example Zellner and Revankar [1970] Cobb-Douglas Production Function OLS Estimator Hypothesis Testing Constant Returns to Scale? Homoscedasticity? Generalized Production Function Output Effects? Instrumental Variables GAUSS/GPE2 Program and Data
References K.-P. Lin, Computational Econometrics: GAUSS Programming for Econometricians and Financial Analysts, ETEXT Publishing, Los Angeles, 2001. C.-F. Chung, Learning Econometrics with GAUSS, Institute of Economics, Academia Sinica, 2000. A. Zellner and N. Revankar, "Generalized Production Functions," Review of Economic Studies, 1970, 241-250.