*********************************************************************************** * ewar(final).prg * This RATS code estimates the extent to which movements in the change of the * exchange rate (ds) is due to movements in the unobservable shock nu. This * is quantified by the ration variance(nu)/variance(ds). * This program applies to VAR processes. *********************************************************************************** * The methodology is due to Charles Engel and Kenneth West (2003). * Department of Economics. University of Wisconsin-Madison. * Program written by Camilo E. Tovar * Last updated November 16 2003. *********************************************************************************** CAL 1974 1 4 ALL 200 2003:1 OPEN DATA C:\Documents and Settings\ctovar\My Documents\Charles PA JOB\RATS\NEW\data_ew.rat DATA(FORMAT=wk1,ORG=obs) / s_ca mm_ca pp_ca yy_ca ii_ca mmyy_ca mmpp_ca mmsw_ca mmswyy_ca mmswpp_ca DATA(FORMAT=wk1,ORG=obs) / s_fr mm_fr pp_fr yy_fr ii_fr mmyy_fr mmpp_fr mmsw_fr mmswyy_fr mmswpp_fr DATA(FORMAT=wk1,ORG=obs) / s_ge mm_ge pp_ge yy_ge ii_ge mmyy_ge mmpp_ge mmsw_ge mmswyy_ge mmswpp_ge DATA(FORMAT=wk1,ORG=obs) / s_it mm_it pp_it yy_it ii_it mmyy_it mmpp_it mmsw_it mmswyy_it mmswpp_it DATA(FORMAT=wk1,ORG=obs) / s_jp mm_jp pp_jp yy_jp ii_jp mmyy_jp mmpp_jp mmsw_jp mmswyy_jp mmswpp_jp DATA(FORMAT=wk1,ORG=obs) / s_uk mm_uk pp_uk yy_uk ii_uk mmyy_uk mmpp_uk mmsw_uk mmswyy_uk mmswpp_uk *********************************************************************************** *********************************************************************************** ******* INSERT THE NUMBER OF VARIABLES USED IN THE VAR **************************** comp varsize = 2; * specifies number of variables in the var. *********************************************************************************** ******* SET THE FUNDAMENTAL: 1=MM ; 2=PP ; 3=YY ; 4=ii ; 5=MMYY **************** ******* 6=MMPP ; 7=MMSW ; 8=MMSWYY ; 9=MMSWPP **************** comp g=5 comp h=2 *********************************************************************************** * Declare variables used in the program decl vect[series] resids8 decl vect[series] varresiduo(varsize); *number in parenthesis must match varsize decl vect[series] coefvar(varsize); *number in parenthesis must match varsize decl rect vr decl rect C decl rect A decl rect B decl rect Id decl rect as decl real az1 az2 Dofor r=201 211 221 231 241 251 disp '****************************************************************' dofor w=1 2 3 4 if w==1; comp bvalue=0.9 else if w==2; comp bvalue=0.95 else if w==3; comp bvalue=0.99 else if w==4; comp bvalue=1 else; disp 'WARNING !!!!!! REVISE PROGRAM' w disp 'COUNTRY DATA FOR:' if r==201; disp 'CANADA' else if r==211; disp 'FRANCE' else if r==221; disp 'GERMANY' else if r==231; disp 'ITALY' else if r==241; disp 'JAPAN' else if r==251; disp 'UNITED KINGDOM' else; disp 'WARNING !!!!!! REVISE PROGRAM' r disp '****************************************************************' comp s=r comp f=r+g comp p=r+h disp 'THE SERIES BEING USED BY THE PROGRAM ARE:' disp 'EXCHANGE RATE:' %l(r) s disp 'FUNDAMENTAL 1:' %l(f) f disp 'FUNDAMENTAL 1:' %l(p) p disp '****************************************************************' disp 'THE DISCOUNT FACTOR IS:' bvalue disp '****************************************************************' ********************* Parameters Setting ************************* comp start=%cal(1974,1) ;** start: The start date of sample period comp end=%cal(2003,1) ;** end: The end date of sample period comp tlags = 4 ;** tlags: number of lags ****************************************************************** disp 'The number of lags being used is:' tlags *Take the first difference of the exchange rate and fundamentals diff s / ds diff f / df diff p / dp *print / s ds f df disp '****************************************************************' * Estimate vector autoregressive process and save residuals as residuo * The variance of the residuals are calculated and save into a matrix vr * also take the estimated coefficients and put them into a matrix A1 * the coefficients are then rearranged so that they can be multiplied * by bvalue^lags SYSTEM(MODEL=EXMODEL) VARIABLES df dp LAGS 1 TO tlags DET constant END(SYSTEM) ESTIMATE(print,RESIDS=RESIDS8,coeffs=coef) start end varresiduo(1) coefvar(1) display '**************************************************************************' ** I now proceed to calculate the variance of the residuals and save them in a matrix vr comp i=1001 comp j=i-1000 *declare rect vr dim vr(1,varsize) comp vr=%const(0) dofor j=1 to varsize *display j comp i=varresiduo(j) statistics(noprint) i start end comp vare = %variance comp nobs= %nobs *display 'Number of observations' nobs *display 'The variance of residuals for equation' j vare comp vr(1,j) = vare comp j=j+1 comp i=i+1 end dofor disp 'The variance of the residuals from the VAR are:' vr *display nobs comp coefsize = varsize*tlags *decl rect C dim C(varsize,coefsize) comp C = %const(0) dofor j=1 to varsize dofor i=1 to coefsize comp C(j,i) = coefvar(j)(i) comp i=i+1 end dofor comp j=j+1 end dofor disp '**************************************************************************' disp 'The values displayed should coincide with the regressions coefficients' disp '**************************************************************************' disp 'C' C disp '**************************************************************************' disp 'Checking that matrix with the coefficients are ordered correctly' disp '**************************************************************************' comp varsize2= varsize*varsize *decl rect A dim A(varsize,coefsize) comp A=%const(0) *disp 'A' A comp size= varsize*2 comp i=1 dofor i = 1 to varsize comp j=0 comp k=1 comp q=tlags dofor w = 1 to size comp j=j+1 comp A(i,j)=C(i,k) comp j=j+1 comp q=q+1 comp A(i,j)=C(i,q) comp k =k+1 comp w=w+1 end dofor comp i=i+1 end dofor *display 'C' C display 'A' A *decl rect B dim B(1,tlags) comp B = %const(0) dofor i=1 to tlags compute be=bvalue**i compute B(1,i) = be end dofor * Calculate the inverse of zeta and zeta matrices *decl rect Id dim ID(varsize,varsize) comp ID=%identity(varsize) *display ID comp phi=%xsubmat(A,1,varsize,1,varsize) comp bphi=B(1,1)*phi comp zetam1=ID-bphi comp i=varsize+1 comp k=2 dofor k=2 to tlags comp j=i+varsize-1 comp phi=%xsubmat(A,1,varsize,i,j) *display 'A' A *display 'phi' phi *display 'B' B(1,k) comp bphi=B(1,k)*phi *display 'bphi' bphi comp zetam1=zetam1-bphi comp i=i+varsize comp k=k+1 end dofor disp '**************************************************************************' disp '*****************Values for zeta inverse and zeta*************************' disp '**************************************************************************' disp 'The inverse of matrix ZETA is: ' zetam1 comp zeta = inv(zetam1) disp 'Matrix ZETA is: ' zeta * Define the vector a in the calculations tr(as)= [1 0] *decl rect as dim as(varsize,1) comp as=%const(0) comp as(1,1)=1 *disp as comp azeta=tr(as)*zeta disp 'The value of tr(a)*zeta is: ' azeta disp '**************************************************************************' * Calculate the as * variance of the residuals * also obtain the effective sample to be used *decl real az1 az2 comp az1 = azeta(1,1) set dshatp = az1*varresiduo(1) comp az2 = azeta(1,2) set dshath = dshatp+az2*varresiduo(2) *print / dshath dshatp statistics(noprint) dshath start end comp vdshath=%variance comp obsavailable=%nobs inquire(series=dshath) initial last disp 'The effective sample to be used is: ' %datelabel(initial) %datelabel(last) disp '**************************************************************************' disp 'The variance of dshat is: ' vdshath *Calculate and display the variance of ds adjusted for missing observations statistics(noprint) ds initial last comp vards = %variance display 'The variance of ds for the adjusted sample is:' vards disp '**************************************************************************' * Calculate nu set nu = ds-dshath *print / ds dshath nu statistics(noprint) nu initial last comp varnu = %variance disp 'The variance of nu is: ' varnu disp '**************************************************************************' * Calculate the ratio of the variance of nu to the variance of ds comp ratio = varnu/vards disp 'The ratio of varnu/vards is: ' ratio comp ratiods = vdshath/vards disp 'The ratio of the variances dshath to ds is: ' ratiods disp '**************************************************************************' cross(noprint,covariances) ds dshath initial last 0 0 covadsdsh display 'The covariance between ds and dshath is:' print(nodates) / covadsdsh disp '**************************************************************************' compute z2varres = (zeta*zeta) * tr(vr) disp 'The value for zeta^2*var(residuals) = ' z2varres *print / f df disp '' disp '' end dofor * Series must be cleaned before being used again in the loop clear s ds f df p dp disp '' disp '' end dofor