/* PROGRAM FINDS EXACT MLE FOR ARMA(2,2) MODELS OF GDP GROWTH PROGRAM DESIGNED BY JAMES MORLEY 2/9/00 Modified by Eric Zivot 4/18/00 */ @INITIAL GAUSS STUFF@ new; @clear memory@ library optmum, pgraph; @call up GAUSS modules for optimization and graphing@ format /m1 /rd 9,6; @set details of output format@ cls; maxflag=1; @LOAD DATA@ load path=c:\research\bn; /* load data[195,1]=gdp4795.prn; @postwar real GDP@ y=ln(data); */ load data[206,1]=lngdpq.txt; y= 100*data; dy=(y[2:206]-y[1:205]); T=rows(dy); @sample size@ @MAXIMUM LIKELIHOOD ESTIMATION@ @starting values for parameters@ @ these are transformed parameters @ @!!!make sure you have the same number of starting values as parameters!!!@ if maxflag==0; @ unrestricted parameters @ prmtr_in={1 0.5 0 0 0 0}; else; @ restricted parameters @ prmtr_in={0.815603 0.969389 1.341860 -0.705913 -1.054292 0.518775}; endif; prmtr_in=prmtr_in'; {xout,fout,gout,cout}=optmum(&lik_fcn,prmtr_in); @calls optmum to calculate MLEs@ prm_fnl=trans(xout); @final constrained point estimates@ lik=-fout; @final likelihood value@ cov0=inv(hessp(&lik_fcn,xout)); grdn_fnl=gradfd(&TRANS,xout); cov=grdn_fnl*cov0*grdn_fnl'; @delta method var-cov for constrained parameters (Kim & Nelson ch.2)@ sd_fnl =sqrt(diag(cov)); @Standard Errors of Parameter Estimates@ @ check stability of AR(2) @ ff = prm_fnl[3]~prm_fnl[4]|1~0; ear=eig(ff); @ check stability of MA(2) @ ff = (-1*prm_fnl[5])~(-1*prm_fnl[6])|1~0; ema=eig(ff); @ compute psi(1) @ psi1 = (1+prm_fnl[5]+prm_fnl[6])/(1-prm_fnl[3]-prm_fnl[4]); @ compute derivate for delta method @ g1 = (1+prm_fnl[5]+prm_fnl[6])/(1-prm_fnl[3]-prm_fnl[4])^2; g2 = 1/(1-prm_fnl[3]-prm_fnl[4]); dg = 0~0~g1~g1~g2~g2; ase = sqrt(dg*cov*dg'); output file=c:\research\bn\arma.out reset; output on; "==FINAL OUTPUT========================================================"; "ARMA(2,2) Estimation"; "likelihood value is ";; lik; "Estimated parameters and asymptotic standard errors:"; "mu sig phi1 phi2 theta1 theta2"; "-------------------------------------------------------------------------------------------------"; prm_fnl'; "(";;sd_fnl';;")"; "-------------------------------------------------------------------------------------------------"; "Inverted roots of AR polynomial"; ear; "Inverted roots of MA polynomial"; ema; "-------------------------------------------------------------------------------------------------"; "Estimates psi(1) and asymptotic se via delta method"; psi1; "(";;ase;;")"; "==============================================================="; output off; END; /*======================================================================== Local procedures ========================================================================*/ PROC LIK_FCN(PRMTR1); local prmtr,mu,sig,phi1,phi2,theta1,theta2,mu_tilda,f,q,h,beta_ll,p_ll, llikv,j,beta_tl,p_tl,aida_tl,f_tl,beta_tt,p_tt; @PARAMETERS@ prmtr=trans(prmtr1); @constrain parameters@ mu=prmtr[1]; @unconditional mean@ sig=prmtr[2]; @standard deviation of error term@ phi1=prmtr[3]; @ar coefficient@ phi2=prmtr[4]; @ar coefficient@ theta1=prmtr[5]; @ma coefficient@ theta2=prmtr[6]; @ma coefficient@ @SET UP STATE SPACE FORM@ MU_TILDA= mu*(1-phi1-phi2)|0|0; F=phi1~phi2~0| 1~0~0| 0~1~0; Q= sig^2~0~0| 0~0~0| 0~0~0; H= 1~theta1~theta2; @INITIAL STATE ESTIMATES@ BETA_LL= 0|0|0; @unconditional expectation of state vector@ P_LL = inv( (eye(rows(F)^2)-F.*.F) )*vec(Q); @see Kim & Nelson, ch. 3@ P_LL= reshape(P_LL,rows(F),rows(F)); llikv = 0; j=1; do until j>T; @KALMAN FILTER@ BETA_TL = F * BETA_LL; P_TL = F* P_LL * F' + Q; AIDA_TL = dy[j] - mu - H * BETA_TL; F_TL = H * P_TL * H'; BETA_TT = BETA_TL + P_TL*H'*INV(F_TL) * AIDA_TL; P_TT = P_TL - P_TL * H'*INV(F_TL) * H * P_TL; @LIKELIHOOD FUNCTION@ llikv=llikv + 0.5*(ln(2*PI*F_TL) + (AIDA_TL^2)/F_TL); @UPDATE FOR NEXT ITERATION@ BETA_LL=BETA_TT; P_LL=P_TT; j=j+1; endo; retp(llikv); endp; @========================================================================@ /*-------------------*/ @PROCEDURE TO CONSTRAIN PARAMETERS@ proc trans(c0); local c1,aaa,ccc; c1 = c0; if maxflag==0; c1[2]=exp(-c0[2]); @positive variance@ @USE THE FOLLOWING CONSTRAINTS FOR ARMA(2,q)@ aaa=c0[3]./(1+abs(c0[3])); ccc=(1-abs(aaa))*c0[4]./(1+abs(c0[4]))+abs(aaa)-aaa^2; c1[3]=2*aaa; c1[4]= -1* (aaa^2+ccc) ; @USE THE FOLLOWING CONSTRAINTS FOR ARMA(p,1)@ /* c1[5]=c0[5]/(1+abs(c0[5])); */ @USE THE FOLLOWING CONSTRAINTS FOR ARMA(1,q)@ /* c1[3]=c0[3]/(1+abs(c0[3])); */ endif; retp(c1); endp; /*-------------------*/