/* -------------------------------------------------------------------------- */ /* BNSTATS.G */ /* calculates and prints variance decomposition for beveridge nelson decomposition. Usage: call bnstats(y,z,c); */ /* -------------------------------------------------------------------------- */ proc(0) = doit(dx,label); local vcv,d,corr,vcorr,sds,mask,fmt; vcv = ( (dx-meanc(dx)')'(dx-meanc(dx)') )/(rows(dx)-1); d = diag(vcv); corr = vcv./((d*d')^(1/2)); /* merge vcv and corr */ corr = lowmat1(corr)-eye(rows(corr)); vcorr = lowmat(vcv)'+corr; sds = diag(vcv)^(1/2); format /RD 10,3; "Standard deviations"; $label'; sds'; " "; "variance-covariance/correlation (below diagonal)"; mask = zeros(1,5)|(zeros(4,1)~ones(4,4)); fmt = "*.*lf"~10~3; call printfm( (" "~label')|(label~vcorr),mask,fmt ); ""; "percent of variance of DGNP"; call printfm( (" "~label')|(label~ lowmat( (100*vcorr./vcorr[1,1])')' ) ,mask,fmt ); endp; proc(0) = bnstats(y,z,c); local sel,s,label; local x; sel = z ./= 0 ; /* eliminate zeros of z */ y = selif(y,sel); /* all series same length */ z = selif(z,sel); c = selif(c,sel); s = y-z; x = y~z~s~c; let label = "y" "z" "s" "c"; dx = x[2:rows(x),.]-x[1:rows(x)-1,.]; ""; "Statistics on first differences of GNP, B-N trend, consumption " ""; call doit(dx,label); dx = x[5:rows(x),.]-x[1:rows(x)-4,.]; ""; "Statistics on fourth differences of GNP, B-N trend, consumption " ""; call doit(dx,label); endp; /* test call */ /* output file=bnstats.out reset; call bnstats(y,z,c); output off; */