Article From: Department of Economics Subject: GMMQ.EXP Posted by: Information Provider Phone Number: (202) 885-3770 E-Mail Address: econ@american.edu Post Date: 23 Sep 1994 Expiration Date: 23 Oct 2004 GMMQ.EXP (Hanson, Heaton, & Ogaki) @ GMMQ.EXP @ @ This file is for Version 2 of GAUSS @ @------------------------------------------------------------------------------ Prepared by Lars P. Hansen, John C. Heaton, and Masao Ogaki Financial support from the National Science Foundation Grant number: SES-8512371 Last Revision: 05/24/91 ------------------------------------------------------------------------------@ /* This program has been used and seems to be free of errors. However, we (Lars P. Hansen, John C. Heaton, and Masao Ogaki) do not assume responsibility for any remaining errors. In no event shall we be liable to for any damages whatsoever arising out of the use of or inability to use this program. This program is for the generalized method of moments (GMM) procedure. See "Generalized Instrumental Variable Estimation of Nonlinear Rational Expectations Models," by L.P. Hansen and K.J. Singleton (Econometrica 1982, Vol.50, 1269-1286). This example file is for Hansen and Singleton model, but uses different data than theirs. @@ To run this example file, type RUN MINQUAD.SET [F4][F2] RUN GMMQ.SET [F4][F2] RUN GMMQ.EXP [F4][F2] The programs MINQUAD.SET and GMMQ.SET define necessary procedures. To use these programs for the user's problem, the user can modify this example file for the user's problem. Usually the user does not have to modify MINQUAD.SET and GMMQ.SET because all the paramters for these two programs are controlled by this example file. @@ The user should go through Step 1-4 and modify this example file for the user's own problem. Model: E[w(t)|I(t)]=0: Disturbance w(t) nw by 1 vector wi(t) is in information set I(t+ri) i=1,2,..,nw h(t,b)=[z(t)w(t)]: Instruments z(t) L by nw matrix z(t) is in I(t). It is assumed that z(t) of the form z(t)=|z1(t) 0 .... 0| | 0 z2(t) 0 .... 0| | | | | 0 .... 0 znw(t)|, so that [z(t)w(t)]'=[w1(t)z1(t)',...,wnw(t)znw(t)']. Algorithm: This program calculates and iterates the following: ititial W0 given. 1. g(b)=C*[h(1,b)+,...,+h(T,b)] b=argmin{g(t,b)'W0*g(t,b)} z(t)w(t)=h(t,b) 2. Rzw(j)=(1/T)[z(1+j)w(1+j)w(1)'z(1)'+,..,+{z(T)w(T)w(T-j)Z(T-j)] j=0,1,..,rm W1=Rzw(0)+{Rzw(1)+Rzw(1)'}+,..,+{Rzw(r)+Rzw(r)'} W0=inv(W1) (W1 can be calculated by other methods depending on the value of calwflag. See below for more explanations.) 3. go back to 1. Here C is a scaling multiplier, and taken to be 'const' or 'const2' depending on whether W0 is I or not, and r=maxc(rwv). See below for more explanations. OUTPUT: chi: chi-square test statistic for the overidentifying restrictioins The following values in GAUSS matrix files: a. Current parameter values in MINQUAD.SET search: crparv.fmt b. Current inverse hessian matrix in MINQUAD.SET search: crhess.fmt c. GMM estimates which uses W0=I: bgmi.fmt d. GMM estimates of the last GMM iteration: bgm.fmt e. W0 calculated from the last GMM iteration results: w0.fmt */ @ ======================== User Definition Area ============================ @ @ ********************************************************************** @ @ ----------- Step 1: Prepare Output File ---------------------------@ @ ********************************************************************** @ output file=gmmq.out reset; @ Specify the name of the output file. @ ? " ************************** GMM Results *********************************"; @ Prepare the following message which will be printed at the top of the output file @ ?" GMMQ.OUT"; ? "Hansen and Singleton Model (multiple assets) (Econometrica '82)"; datestr(0); timestr(0); ? "Parameter Names 'beta,gamma'"; @ *********************************************************************** @ @------------ Step 2: Define Global Variables ------------------------- @ @ *********************************************************************** @ @----------------------------@ @ Section A. User must specify variables in this section. @ @----------------------------@ tend=333; @ # of observations=T; scalar @ bgm=1.2|-97; @ bgm=b(1)|..|b(kgm); kgm by 1 vector Initial values of the coefficients (In this example, the parameters happen to converge to values that are not economically meaningful when W0=I. The initial values are set to values close to the converged valuse in this example, so that this example converges quickly.) @ nw=2; @ # of disturbance terms in w(t); scalar @ nzv=7|7; @ nzv=nz(1)|..|nz(nw); nw by 1 vector For each i, nz(i) is # of elements in zi(t) i=1,..,nw. Let L=sumc(nzv), then L is # of orthogonal condition.@ rwv=1|1; @ rwv=rw(1)|..|rw(nw); nw by 1 vector rw(i) is defined so that wi(t) is in I(t+rw(i)) i=1,..,nw @ @---------------------------------@ @ Section B. User can leave the variables in this section as they are, and go to STEP 3. Only advanced users should modify this section.@ @---------------------------------@ gradname=&GRAD2; @ Specify the name of proc that calculates the gradient dgT(b)/db. @ const=1/sqrt(tend); @ Scaling Multiplier when W0=eye(L) @ const2=1/sqrt(tend); @ Scaing Multiplier when W0 is not eye(L) @ @ These scaling multipliers should be set so that the value of function (vof) in nonlinear search of MINQUAD.SET is near 1. If vof is too close to 0, the search will not work properly. const2=1/sqrt(tend) will generally be good. @ w0flag=0; @ scalar; If w0flag=0, W0=I is used as the initial weighing matrix W0. If w0flag=1, initial bgm is used to calculate initial W0. If w0flag=2, W0 in the memory is used as initial W0. If w0flag=3, W0 and bgm in the memory are used to give the first GMM result. @ maxitegm=2; @ Sets maximum # of iteration over weighting matrix, W0. Set w0flag=0 and maxitegm=2 to execute usual 2-Stage GMM. @ zero=1E-2; @ Iteration over W0 continues until the maximum difference of the current and the previous W0 in absolute value becomes less than 'zero', or the # of iteration exceeds maxitegm. @ calwflag=0; @ This variable is used to choose the method to calculate the distance matrics, W0. If calwflag=0, Durbin's method will be used when W0 is singular. If calwflag=1, Newey and West Method will be used when W0 is singular. If calwflag=2, Parzen's lag window will be used when W0 is singular. If calwflag=3, Durbin's method will be used. If calwflag=4, Newey and West Method will be used. If calwflag=5, Parzen's lag window will be used. Durbin's method imposes zero restrictions while Newey and West method dose not. @ ordard=floor(sqrt(8190/sumc(nzv)^2)); @ Order of AR representation for Durbin's method when W0 is singular @ lend=15; @ Order of lags used for Newey and West method @ @ See MINQUAD.SET for the following globals @ hflag=2; dfpflag=1; sstol=1e-25; @ See MAXMUM.DOC on MODULE9 of GAUSS for the following globals @ gradtol=1e-5; btol=1e-5; typf=1; typb=1; @ *************************************************************** @ @ ----------- Step 3: READING IN DATA --------------------------- @ @ *************************************************************** @ load x[335,3]=gmmq.dat; c=x[.,1]; @ c(t)/c(t-1) @ re=x[.,2]; @ vwr @ rf=x[.,3]; @ T-Bill rate @ clear x; @ ******************************************************************** @ /* ------------------------------------------------------------------- Step 4: Define the proc hu(b) that returns tend by L matrix |[z(1)w(1)]' | | | | |[z(tend)w(tend)]'| where [z(t)w(t)]'=[w1(t)z1(t)',...,wnw(t)znw(t)'] ----------------------------------------------------------------------- */ @ ********************************************************************** @ @ The proc must have the name "hu", and should take only one argument. @ @ Note that the proc "hu" will be called many times in GMM procedure. If some calculations can be done outside the proc, that will speed up the program. For example, here vectors of instrumental variables are constructed outside the proc. @ @ Constructing instrumental variables @ zp=ones(tend,1)~c[1:tend,.]~re[1:tend,.]~rf[1:tend,.]; zp=zp~c[2:tend+1,.]~re[2:tend+1,.]~rf[2:tend+1,.]; @ Now define the proc "hu" @ proc hu(b); local ps,w1,w2,zw1,zw2; ps=b[1,1].*(c[3:335,.]^(b[2,1]-1)); w1=ps.*re[3:335,.]-1; w2=ps.*rf[3:335,.]-1; zw1=zp.*w1; zw2=zp.*w2; retp(zw1~zw2); endp; @=========== The User does not have to change the code below. ============== @ @--------------------- Print results of estimation---------------------@ proc (0)=prntrslt(x,s); ? " --------------- Minimization Results ---------------------- Step size: " s " Value of the objective function: " vof " Minimiser is" x' " -----------------------------------------------------------"; endp; @ ------------------------------------------------------------------------- @ @ ************************************************************************ @ @ THE PROGRAM STARTS @ chi=gmmq(gradname,tend,nzv,rwv,nw,rows(bgm),zero,maxitegm); output off; @ ------------------------ END OF PROGRAM --------------------------------- @ ************************************************************************ Department of Economics is entirely responsible for the information provided above. Please direct any comments to Information Provider at: E-Mail Address: econ@american.edu Phone Number: (202) 885-3770