
/**************   King-Plosser-Stock-Watson   *****************
Author: Tommaso Proietti <tommaso@stat.unipg.it>
	Dipartimento di Scienze Statistiche
	Via A. Pascoli C.P. 1315 Succ. 1
	06100 PERUGIA
	Tel +39-75-585.5238 Fax +39-75-43242
Date: Sep 17 1997
The following code is provided without performance guarantees
for public, non-commercial use.
It implements the results in the paper
T. Proietti: "Short run dynamics in cointegrated systems"
Oxford Bull. of Econ. & Stats, vol 59, n.3, August 1997.
****************************************************************\

new;
clearg  P,v,F,c,se,matrice,b,a,matheta,P0,psi;
load x[168,3]=vahid.dat;
yp = x[.,1]; cp = x[.,2]; ip = x[.,3];
xe=x;
dx=x-lagn(x,1);
alpha={0.0008475 0.0027652,
       0.0011626 0.00017192,
       0.0072931 0.0029399};           @ ADJUSTMENT MATRIX @
beta={-24.199 -9.8959  33.98,
       86.852 -69.328 -13.791};        @ COINTEGRATING VECTORS @
beta=beta';
mu={0.089131, -.049063, -0.24328};     @ drift @
@ COEFFICIENT MATRICES of VAR in levels:
  A(L)X_t=m+e_t  (equation (1) in Proietti (1997)
  estimated with cointegration restriction @
A1={0.91342 0.35968 0.12559,    0.12784 0.90577 -0.02743,
    0.68376 0.17881 1.0382};
A2={-0.04348 -.11068 -.12044, -.10089 .30126 -.0075852,
    -0.57843 0.18073 -.29979};
A3={-.069199 -.085972 -.020968, -.19592 -.037897 0.055989,
    -.26562 0.052988 0.11497};
A4={-.14655 .19125 .036807, .099377 -.068204 -.049844,
    -.22236 .26137 -.056404};
A5={.10323 -.20718 -.020511, -.030863 -.033333 -.017194,
    .16139 .024051 -.0634};
A6={.075568 .07219 .010152, .16844 -.061426 .012548,
    .0087417 -.10785 .22311};
A7={-.13115 .16683 -.014545, -.12111 .26723 -.015021,
    -.050925 .33513 -.18006};
A8={0.07851 -.18603 .013247, .066325 -.24998 .0047173,
    0.1846 -.64923 .016154};
@ INTERIM MULTIPLIER REPRESENTATION (equation (13) in Proietti (1997))@
I3=eye(3);
g1=A1-I3; g2=g1+A2; g3=g2+A3; g4=g3+A4; g5=g4+A5; g6=g5+A6; g7=g6+A7;
sgamma=g1+g2+g3+g4+g5+g6+g7;
gg0=sgamma;gg1=gg0-g1;gg2=gg1-g2;gg3=gg2-g3;gg4=gg3-g4;gg5=gg4-g5;gg6=gg5-g6;
ga=inv(eye(3)-sgamma+alpha*beta');
@"Projection matrix: cadga (denoted P in the paper - bottom page 409)  @
cadga=ga*alpha*inv(beta'ga*alpha)*beta';
C1=(eye(3)-cadga)*ga;           @ TOTAL MULTIPLIER @
@ SHORT RUN DYNAMICS ALONG THE ATTRACTOR
  (transitory component in the Gonzalo Granger decomposition) @
cad=cadga*x'-ga*alpha*inv(beta'ga*alpha)*inv(beta'ga*alpha)*beta'ga*mu;
@ SHORT RUN DYNAMICS: Psi_{2t} in the paper @
dxm=(dx'-(c1*mu) .* ones(1,rows(dx)))';
srd=-C1*(gg0*dxm'+gg1*lagn(dxm,1)'+gg2*lagn(dxm,2)'+gg3*lagn(dxm,3)'+
         gg4*lagn(dxm,4)'+
         gg5*lagn(dxm,5)'+gg6*lagn(dxm,6)');
srd=srd';
/**********************************************************************/
bncic=srd+cad';  @ Beveridge-Nelson cycle @
bntr=x-bncic;    @ Beveridge-Nelson trend @
/**********************************************************************/
library pgraph;graphset;
fonts("simplex complex microb simgrma");
xtics(3,168,4,0);
lab = "\20347 \20348 \20349 \20350 \20351 \20352 \20353 \20354
\20355 \20356 \20357 \20358 \20359 \20360
\20361 \20362 \20363 \20364 \20365 \20366 \20367 \20368
\20369 \20370 \20371 \20372 \20373 \20374 \20375 \20376
\20377 \20378 \20379 \20380 \20381 \20382 \20383
\20384 \20385 \20386 \20387 \20388 \20389";
asclabel(lab,0);
_pltype={6,4,6,3,6};
_protate=0;
_plwidth=2.5;
_ptitlht=.23;

graphprt("-c=1 -cf=vahid1.out -w=10");
begwind;
window(2,2,0);
setwind(1);
 title("Fig.1: GNP and Beveridge-Nelson Trend");
    _pltype={6 4}; _plegctl={2 7 5.2 .8};
    _plegstr = "GNP \000BN Trend";
    xy(seqa(1,1,rows(yp)),yp~bntr[.,1]);
nextwind;
 title("Fig. 2: BN cycle and GG cycle for GNP");
    _plegctl={2 5 4.2 .6}; _plegstr = "BN \000GG";
    _pline={1 1 1 0 168 0 1 10 0};
    xy(seqa(1,1,rows(yp)),bncic[.,1]~cad[1,.]');
nextwind;
 title("Fig. 3: Consumption and Beveridge-Nelson Trend");
    _plegctl={2 7 5.2 .8}; _plegstr = "Consumption \000BN Trend";
    xy(seqa(1,1,rows(cp)),cp~bntr[.,2]);
nextwind;
 title("Fig. 4: BN cycle and GG cycle for Consumption");
    _plegctl={2 5 4.2 .6}; _plegstr = "BN \000GG";
    xy(seqa(1,1,rows(cp)),bncic[.,2]~cad[2,.]');
endwind;
graphprt("-c=1 -cf=vahid2.out -w=10");
begwind;
window(2,2,0);
setwind(1);
 title("Fig. 5: Investment and Beveridge-Nelson Trend");
    _pltype={6 4}; _plegctl={2 7 5.2 .8};
    _plegstr = "Investment  \000BN Trend";
    xy(seqa(1,1,rows(ip)),ip~bntr[.,3]);
nextwind;
 title("Fig. 6: BN cycle and GG cycle for Investment");
    _plegctl={2 5 4.2 .6}; _plegstr = "BN \000GG";
    _pline={1 1 1 0 168 0 1 10 0};
    xy(seqa(1,1,rows(yp)),bncic[.,3]~cad[3,.]');
nextwind;
 title("Fig. 7: Short run dynamics along the attractor");
    _plegctl={0 0 0 0}; _plegstr = "";
    xy(seqa(1,1,rows(srd)),srd@[.,2]@);
nextwind;
 imp=eye(3)-cadga;
 {q1,q2}=lu(imp);
 ctt=q2[1,.];
 ctgg=x * ctt';
 imd=(xe'-g1*lagn(xe,1)'-g2*lagn(xe,2)'-g3*lagn(xe,3)'-
         g4*lagn(xe,4)'-
         g5*lagn(xe,5)'-g6*lagn(xe,6)'-g7*lagn(xe,7)')';
 tem=seqa(1,1,rows(yp));
 ctbn=imd*ctt';
 cal=null(alpha');  cal=-cal;
 ctbn=imd*ctt'+cal'*mu;
 ctbn2=imd*cal; ctgg2=xe*cal;
 th2=imp*cal; loade=th2/th2[1];
 calnew=th2[1]*cal;
 ctbn2=imd*calnew; ctgg2=xe*calnew;
 calle=cal'(eye(3)-sgamma);
 ctbn3=imd*calle'; ctgg3=xe*calle';
title("Fig. 8: BN common trend and GG common factor");
    _plegctl={2 7 5.2 .8}; _plegstr = "BN \000GG";
    xy(seqa(1,1,rows(yp)),ctbn2~ctgg2);
endwind;
end;
/********data*********************************************************
 2.1601      1.8722      .55222
 2.1614      1.8847      .52059
 2.1609      1.8817      .55341
 2.1751      1.8767      .62404
 2.1764      1.8824      .64792
 2.1793      1.8902      .65234
 2.1776      1.8892      .63944
 2.1750      1.8954      .63063
 2.1562      1.8944      .57237
 2.1363      1.9038      .52538
 2.1376      1.8987      .51688
 2.1256      1.9037      .54391
 2.1755      1.9165      .60033
 2.2124      1.9331      .68722
 2.2471      1.9701      .75354
 2.2677      1.9535      .73847
 2.2574      1.9749      .70225
 2.2606      1.9578      .66838
 2.2600      1.9675      .65719
 2.2454      1.9716      .64877
 2.2472      1.9737      .66055
 2.2318      1.9899      .66850
 2.2319      1.9927      .60858
 2.2556      2.0114      .66676
 2.2573      2.0146      .69575
 2.2602      2.0173      .69591
 2.2513      2.0143      .69184
 2.2333      2.0112      .68377
 2.2361      2.0125      .66802
 2.2459      2.0186      .68267
 2.2661      2.0319      .71103
 2.2897      2.0468      .72271
 2.3149      2.0589      .76021
 2.3314      2.0712      .79683
 2.3414      2.0782      .81360
 2.3537      2.0921      .81729
 2.3476      2.0921      .79599
 2.3466      2.0909      .79772
 2.3467      2.0910      .79397
 2.3539      2.0983      .77842
 2.3521      2.1022      .77335
 2.3465      2.1013      .75881
 2.3504      2.1049      .76619
 2.3266      2.1044      .74649
 2.2912      2.0911      .69150
 2.2903      2.0988      .65699
 2.3152      2.1107      .66196
 2.3363      2.1171      .71450
 2.3535      2.1290      .76735
 2.3753      2.1386      .79708
 2.3670      2.1443      .80286
 2.3765      2.1444      .78760
 2.3921      2.1452      .80867
 2.3797      2.1550      .77524
 2.3745      2.1478      .74573
 2.3569      2.1463      .74222
 2.3593      2.1444      .73046
 2.3705      2.1549      .73495
 2.3830      2.1529      .75545
 2.4011      2.1690      .78380
 2.4121      2.1777      .80007
 2.4215      2.1834      .82860
 2.4254      2.1875      .83093
 2.4172      2.1939      .81404
 2.4283      2.1966      .81571
 2.4428      2.1979      .85827
 2.4548      2.2076      .87850
 2.4591      2.2106      .90101
 2.4815      2.2254      .91153
 2.4864      2.2380      .90916
 2.4969      2.2511      .91260
 2.4976      2.2494      .91845
 2.5223      2.2621      .96368
 2.5299      2.2691      .99127
 2.5404      2.2825      .99992
 2.5580      2.3038      1.0195
 2.5763      2.3123      1.0412
 2.5710      2.3138      1.0270
 2.5705      2.3205      1.0188
 2.5682      2.3206      .97563
 2.5620      2.3248      .94529
 2.5639      2.3339      .97559
 2.5746      2.3341      .98253
 2.5752      2.3356      1.0103
 2.5828      2.3512      1.0325
 2.5961      2.3612      1.0215
 2.6021      2.3748      1.0256
 2.5972      2.3740      1.0499
 2.6145      2.3805      1.0604
 2.6107      2.3825      1.0584
 2.6168      2.3839      1.0646
 2.6094      2.3873      1.0294
 2.5998      2.3885      1.0122
 2.5982      2.3876      .98638
 2.6073      2.3908      1.0023
 2.5901      2.3822      1.0063
 2.6207      2.3923      1.0154
 2.6168      2.3946      1.0455
 2.6163      2.3942      1.0589
 2.6103      2.4009      1.0687
 2.6225      2.4034      1.1044
 2.6432      2.4145      1.1111
 2.6551      2.4228      1.1165
 2.6740      2.4410      1.1638
 2.6952      2.4491      1.1940
 2.6951      2.4423      1.1896
 2.6945      2.4415      1.1828
 2.6968      2.4319      1.1707
 2.6830      2.4152      1.1399
 2.6758      2.4159      1.1201
 2.6577      2.4166      1.0879
 2.6418      2.3984      1.0227
 2.6092      2.4010      .94848
 2.6175      2.4134      .93351
 2.6310      2.4181      .95173
 2.6415      2.4227      .96648
 2.6623      2.4391      .99706
 2.6643      2.4418      1.0058
 2.6651      2.4478      1.0085
 2.6733      2.4587      1.0523
 2.6855      2.4683      1.0860
 2.6977      2.4664      1.1340
 2.7145      2.4717      1.1474
 2.7074      2.4810      1.1495
 2.7145      2.4813      1.1588
 2.7452      2.4964      1.2134
 2.7472      2.4967      1.2211
 2.7580      2.5018      1.2243
 2.7552      2.5013      1.2265
 2.7498      2.4954      1.2205
 2.7546      2.4977      1.2295
 2.7469      2.4975      1.2165
 2.7527      2.4920      1.1981
 2.7162      2.4674      1.0879
 2.7145      2.4744      1.0844
 2.7280      2.4806      1.1221
 2.7450      2.4807      1.1317
 2.7375      2.4772      1.1369
 2.7382      2.4783      1.1252
 2.7151      2.4692      1.0877
 2.6937      2.4718      1.0462
 2.6963      2.4736      1.0115
 2.6783      2.4759      .97656
 2.6702      2.4859      .99512
 2.6827      2.4907      .99525
 2.7073      2.5075      1.0482
 2.7217      2.5176      1.1033
 2.7450      2.5280      1.1460
 2.7683      2.5330      1.1801
 2.7725      2.5460      1.2175
 2.7763      2.5481      1.2286
 2.7754      2.5555      1.2431
 2.7837      2.5698      1.2484
 2.7849      2.5753      1.2652
 2.7835      2.5890      1.2490
 2.7888      2.5907      1.2750
 2.8067      2.5958      1.2604
 2.7926      2.6019      1.2592
 2.7910      2.6121      1.2497
 2.7916      2.6146      1.2547
 2.8042      2.6129      1.2376
 2.8163      2.6211      1.2577
 2.8228      2.6290      1.2783
 2.8366      2.6256      1.2773
 2.8555      2.6395      1.2886
 2.8623      2.6439      1.3172
 2.8703      2.6501      1.3178
 2.8676      2.6564      1.3036
**************  end data **********************/