@ This Gauss program simulates draws from Bayesian posterior distribution
    using importance sampling and is based on Hamilton's (2001) program.
     Sample: 1960:I - 2000:IV, US data @


    output file = junk reset;
    library pgraph, optmum;
    graphset; optset;


format 16,8;

/* loading quarterly data */

nt=164; 
n=nt;

load gdp[nt,4]= ..\data\nrphgdp.txt;

@ Quarterly data, 1960:I - 2000:IV
     col.1 = nominal GDP
     col.2 = real GDP
     col.3 = Potential GDP
     col.4 = Hodrick-Prescott filtered real GDP series @

/* loading monthly Federal Funds rate */

ns = 492;
nn = ns;

load mint[ns,1] = ..\data\mffr.txt;

@ Monthly, 1960:1 - 2000:12 @


/* loading expected inflation of FRB PHiladelphia and Green Book */

np = 129; 
nm = 276;
ng = 125;

load egdpdf[np,2 ] =  ..\data\psgdpdff.txt; 

@ Inflation forecasting from Philadelphia, 
    Quarterly data from 1968:IV - 2000:IV, 
    co.1: previous median of GDP deflator
    col.2: current median forecast of GDP deflator @

load gbinf[ng,5] = ..\data\gbinff.txt; 

@ Inflation forecasting from Green Book in FRB Philadelphia, 
    Quarterly 1965:IV - 1996:IV,
    col.1 = current quarter
    col.2 - col.5 = from one-quarter ahead to four-quarter ahead @

load infvar[nt,1] = ..\data\cvarinf.txt; 

@ Conditional variance of inflation from 1961:2 - 2000:4
     1960:1 - 1961:1 = 0 for nobs 5
     GARCH(1,1) model from inflation process @

/* generating GDP gap */


gg = 1; @ ggap = 1 for the GDP gap based on the CBO Potential GDP
                 ggap = 2 for the GDP gap based on Hodrick-Prescott detrended output @

do until gg > 2;
nt = 164;

if gg == 1;
gdpgap = ((gdp[.,2] - gdp[.,3])./ gdp[.,3]) * 100;
" ********* Test and Estimation based on CBO output gap measure ******";"";
else;    
gdpgap = ((gdp[.,2] - gdp[.,4])./ gdp[.,4]) * 100;
"";" ******** Test based on Hodrick-Prescott output gap measure *******";"";
endif;

/* Generating inflation from the GDP deflator */

gdpdf = (gdp[.,1] ./ gdp[.,2]) * 100;
ginf = (ln(gdpdf[2:nt,1]) -ln(gdpdf[1:nt-1,1])) * 400;  
ginf = zeros(1,1)|ginf; 
inf = ginf; @ annualized quarterly inflation @

/* generating quarterly interest rate */

qint = zeros(nt,1);
i = 1;
do until i>164;
qint[i,1] = mint[3*i-2,1]; @ interest at the first month of the quarter @
i = i+1;
endo;

/* 1-year arithmetic average of current and past interest and inflation rates */

intbar = zeros(nt,1); 
infbar = zeros(nt,1); 

i = 1;
do until i>nt-3;
intbar[i+3,1] = sumc(qint[i:i+3,1])/4;
i = i+1;
endo;

 j = 1;
do until j>nt-4;
infbar[j+4,1] = sumc(inf[j+1:j+4,1])/4;
j = j +1;
endo;

rintbar = intbar[.,1] - infbar[.,1]; @ average real interest rate @

/* Inflation forecasting equation */

linf = inf[5:nt-1,1]~inf[4:nt-2,1]~inf[3:nt-3,1]~inf[2:nt-4,1];
x1 = ones(nt-5,1)~linf~gdpgap[5:nt-1,1];
 y1 = inf[6:nt,1];

  b1 = invpd(x1'*x1)*x1'*y1;
  eps1 = y1 - x1*b1;
  infhat = x1*b1;
  sigols = sumc(eps1^2)/(rows(x1)-cols(x1));
  sigmle = sumc(eps1^2)/rows(x1);
  rsqure = (b1'*x1'*x1*b1)/(y1'*y1);
  rbarsq = 1 - (((nt-5-1)/(nt-5-6))*(1-rsqure));
  ss = sigols*invpd(x1'*x1);

"1. Estimation of inflation process";
      ""; "a. ols coefficients";b1';
     "b. ols see";;sqrt(sigols);
    "c. mle see";;sqrt(sigmle);
    "d. standard errors";sqrt(diag(ss))';
    "e. rbarsquare"; rbarsq; "";

/* gdp gap forecasting equation */

lgdpgap = gdpgap[5:nt-1,1]~gdpgap[4:nt-2,1]~gdpgap[3:nt-3,1]; 
x2 = ones(nt-5,1)~lgdpgap~rintbar[5:nt-1,1]; 
y2 = gdpgap[6:nt,1];
  b2 = invpd(x2'*x2)*x2'*y2;
  eps2 = y2 - x2*b2;
  gdpghat = x2*b2;
  sigols = sumc(eps2^2)/(rows(x2)-cols(x2));
  sigmle = sumc(eps2^2)/rows(x2);
  rsqure = (b2'*x2'*x2*b2)/(y2'*y2);
  rbarsq = 1 - (((nt-5-1)/(nt-5-6))*(1-rsqure));
  ss = sigols*invpd(x2'*x2);

"2. Estimation of GDP gap";
      ""; "a. ols coefficients";b2';
     "b. ols see";;sqrt(sigols);
    "c. mle see";;sqrt(sigmle);
    "d. standard errors";sqrt(diag(ss))';
    "e. rbarsquare"; rbarsq; "";


/* The estimated inflation target of Clarida, Gali, and Gertler (2000) */ 

infts1 = 4.24; @ estimated inflation target in the Pre-Volcker (1960:I - 1979:II) @
infts2 = 3.58; @ estimated inflation target in the Volcker-Greenspan (1979:III - 2000:IV) @

ns1 = 78; @ obs in the pre-Volcker period @
ns2 = 86; @ obs in the second sample @

/* One-quarter ahead expected inflation deviation from the inflation target */
infhat = zeros(5,1)|infhat;
infgap1 = infhat[1:ns1,1] - 4.24; @ pre-Volcker period @ 
infgap2 = infhat[ns1+1:nt,1] - 3.58; @ Volcker-Greenspan period @
infgap = infgap1| infgap2;

/* One-quarter ahead expected GDP gap */
gdpghat = zeros(5,1)|gdpghat;

/* Nonlinear specification for the inflation */

lninf = inf[5:nt-1,1]~inf[4:nt-2,1]~inf[3:nt-3,1]~inf[2:nt-4,1];
x3 = ones(nt-5,1)~lninf~gdpgap[5:nt-1,1]~gdpgap[5:nt-1,1]^2~gdpgap[5:nt-1,1]^3; 
y3 = inf[6:nt,1];

  b3 = invpd(x3'*x3)*x3'*y3;
  eps3 = y3 - x3*b3;
  ninfhat = x3*b3;

ninfhat = zeros(5,1)|ninfhat;
ninfgap1 = ninfhat[1:ns1,1] - 4.24; @ pre-Volcker period @ 
ninfgap2 = ninfhat[ns1+1:nt,1] - 3.58; @ Volcker-Greenspan period @
ninfgap = ninfgap1| ninfgap2;

/* Nonlinear specification for the output gap */

lngdpgap = gdpgap[5:nt-1,1]~gdpgap[4:nt-2,1]~gdpgap[3:nt-3,1];
nrintbar = rintbar[5:nt-1,1]~rintbar[5:nt-1,1]^2~rintbar[5:nt-1,1]^3;
x4 = ones(nt-5,1)~lngdpgap~nrintbar;
y4 = gdpgap[6:nt,1];

  b4 = invpd(x4'*x4)*x4'*y4;
  eps4 = y4 - x4*b4;
  ngdpghat = x4*b4;

ngdpghat = zeros(5,1)|ngdpghat;

ksp = 1; @ use ksp = 1 for whole sample in the forward-looking model 
                         ksp = 2 for the subsample, 1960:1 - 1979:2, in the forward-looking model
                         ksp = 3 for the subsample, 1979:3 - 2000:4, in the forward-looking model
                         ksp = 4 for the whole sample in the backward-looking model
                         ksp = 5 for the pre-Volcker period in the backward-looking model
                         ksp = 6 for the Volcker-Greenspan period in the backward-looking model
                         ksp = 7 for the Model 1 forward-looking model
                         ksp = 8 for the Model 1 backward-looking model
                         ksp = 9 for the Model 2 forward-looking model
                         ksp = 10 for the Model 2 backward-looking model
                         ksp = 11 for the Model 3 forward-looking model
                         ksp = 12 for the Model 3 backward-looking model
                         ksp = 13 for the Model 4 forward-looking model
                         ksp = 14 for the Model 4 backward-looking model
                         ksp = 15 for Robust analysis: W, SPF, CBO, Linear  (Table A.1)
                         ksp = 16 for Robust analysis: 65:IV - 96:IV, Greenbook, CBO, Linear (Table A.1)
                         ksp = 17 for Robustness analysis: 79:III - 00:IV, SPF, CBO, Linear (Table A.1)
                         ksp = 18 for Robustness analysis: 79:III - 96:IV, Greenbook, CBO, Linear (Table A.1)
                         ksp = 19 for Robustness analysis: 83:I - 00:IV, CBO, Linear (Table A.1)
                         ksp = 20 for Robustness analysis: 83:I - 00:IV, SPF, CBO, Linear (Table A.1)
                         ksp = 21 for Robustness analysis: W, CBO, Nonlinear (Table A.1)
                         ksp = 22 for Robustness analysis: Pre-Volcker, CBO, Nonlinear (Table A.1)
                         ksp = 23 for Robustness analysis: Volcker-Greenspan, CBO, Nonlinear (Table A.1) @

khp = 1; @ use khp = 24 for Robustness analysis: W, HP, Linear (Table A.1)
                         ksp = 25 for Robustness analysis: pre-Volcker, HP, Linear (Table A.1)
                         ksp = 26 for Robustness analysis: Volcker-Greenspan, HP, Linear (Table A.1)
                         ksp = 27 for Robustness analysis: 83:I - 00:IV, HP, Linear (Table A.1)
                         ksp = 28 for Robustness analysis: W, HP, Nonlinear (Table A.1)
                         ksp = 29 for Robustness analysis: Pre-Volcker, HP, Nonlinear (Table A.1)
                         ksp = 30 for Robustness analysis: Volcker-Greenspan, HP, Nonlinear (Table A.1)  @


if gg ==1;

do until ksp > 23;
nt = 164;
  
/* The test of nonlinearity: Whole sample, CBO, forward-looking rule model */
if ksp ==1; 
  y = qint[6:nt,1];
  x =infgap[6:nt,1]~gdpghat[6:nt,1]; 
  xlin = x~qint[5:nt-1,1]~qint[4:nt-2,1];
  nt = nt-5;
  n = nt;
"";"3. The test of nonlinearity: Whole sample, CBO, Forward-looking model";"";
endif;

/* The the test of nonlinearity: pre-Volcker, CBO, Forward-looking model */ 

if ksp == 2;
  y = qint[6:ns1,1];
  x = infgap[6:ns1,1]~gdpghat[6:ns1,1];
  xlin = x~qint[5:ns1-1,1]~qint[4:ns1-2,1];
  nt = ns1 - 5;
  n = nt;
"";"4.a The test of nonlinearity:
pre-Volcker period, CBO, Forward-looking rule model"; "";
endif;


/* The test of nonlinearity: Volcker-Greenspan period, CBO, forward-looking model */

if ksp == 3;
  y = qint[ns1+2:nt,1];
  x = infgap[ns1+2:nt,1]~gdpghat[ns1+2:nt,1];
  xlin =x~qint[ns1+1:nt-1,1]~qint[ns1:nt-2,1];
  nt = ns2-1;
  n = nt;
"";"5. The test of nonlinearity: 
Volcker-Greenspan period, CBO, forward-looking rule model"; "";
endif;



/* 6. The test of nonlinearity: Whole sample, CBO, backward-looking model */

if ksp == 4;
  y = qint[3:nt,1];
  x =inf[2:nt-1,1]~gdpgap[2:nt-1,1]; 
  xlin = x~qint[2:nt-1,1]~qint[1:nt-2,1]; 
  nt = nt-2;
  n = nt;
"";"6. The test of nonlinearity: Whole sample, CBO, backward-looking model"; "";
endif;

/* 7a. The test of nonlinearity and estimation
for the pre-Volcker period in the forward-looking model */

if ksp == 5;
  y = qint[3:ns1,1];
  x = inf[2:ns1-1,1]~gdpgap[2:ns1-1,1];
  xlin = x~qint[2:ns1-1,1]~qint[1:ns1-2,1];
  nt = ns1 - 2;
  n = nt;
"";"7.a The test of nonlinearity and estimation:
pre-Volcker period, CBO, backward-looking model"; "";
endif;


/* 8.a The test of nonlinearity: Volcker-Greenspan period, CBO, backward-looking model */

if ksp == 6;
  y = qint[ns1+2:nt,1];
  x = inf[ns1+1:nt-1,1]~gdpgap[ns1+1:nt-1,1];
  xlin =x~qint[ns1+1:nt-1,1]~qint[ns1:nt-2,1];
  nt = ns2-1;
  n = nt;
"";"8.a The test of nonlinearity: Volcker-Greenspan, CBO, backward-looking model";"";
endif;


/* Alternative nonlinear specification: Model 1 in the forward-looking model */

if ksp == 7;
tinfgap = zeros(nt,1); @ if expected inflation gap > 0, tinfgap = infgap, otherwise tinfgap = 0 @
tgdpghat = zeros(nt,1); @ if expected output gap > 0, tgdpghat = gdpghat, otherwise tgdpghat = 0 @

j = 1;
do until j>nt;
if infgap[j,1]>0;
  tinfgap[j,1] = infgap[j,1];
else;
  tinfgap[j,1] = 0;
endif;

if gdpghat[j,1]>0;
  tgdpghat[j,1] = gdpghat[j,1];
else;
  tgdpghat[j,1] = 0;
endif;
j = j+1;
endo;

  y = qint[6:ns1,1];
  x = infgap[6:ns1,1]~gdpghat[6:ns1,1];
  xlin = x~qint[5:ns1-1,1]~qint[4:ns1-2,1]~tinfgap[6:ns1,1]~tgdpghat[6:ns1,1];
  nt = ns1 - 5;
  n = nt;
"";"9.a The test of nonlinearity for the Model 1 forward-looking model";"";
endif;



/* Alternative nonlinear specification: Model 1 in the backward-looking model */

if ksp == 8;
tinf = zeros(nt,1);
tgdpgap = zeros(nt,1);

j = 2;
do until j>ns1;
  if inf[j,1]>4.24;
  tinf[j,1] = inf[j,1];
  else;
  tinf[j,1] = 0;
  endif;
  if gdpgap[j,1]>0;
  tgdpgap[j,1] = gdpgap[j,1];
  else;
  tgdpgap[j,1] = 0;
  endif;
j = j + 1;
endo;

k = ns1+1;
do until k>nt;
  if inf[k,1]>3.58;
  tinf[k,1] = inf[k,1];
  else;
  tinf[k,1] = 0;
  endif;
  if gdpgap[k,1]>0;
  tgdpgap[k,1] = gdpgap[k,1];
  else;
  tgdpgap[k,1] = 0;
  endif;

k = k + 1;
endo;

  y = qint[3:ns1,1];
  x = inf[2:ns1-1,1]~gdpgap[2:ns1-1,1];
  xlin = x~qint[2:ns1-1,1]~qint[1:ns1-2,1]~tinf[2:ns1-1,1]~tgdpgap[2:ns1-1,1];
  nt = ns1 - 2;
  n = nt;
"";"9.b The test of nonlinearity for the Model 1 backward-looking model";"";
endif;


/* Alternative nonlinear specification: Model 2 in the forward-looking model */
if ksp == 9;
binfgap = zeros(nt,1); @ if gdpgap (t-1) > 0, binfgap = infgap, otherwise binfgap = 0 @
bgdpghat = zeros(nt,1); @ if gdpgap (t-1) >0, bgdpghat = gdpghat, otherwise bgdpghat = 0 @

s = 2;
do until s>nt;
  if gdpghat[s-1,1]>0;
  binfgap[s,1] = infgap[s,1];
  bgdpghat[s,1] = gdpghat[s,1];
  else;
  binfgap[s,1] = 0;
  bgdpghat[s,1] = 0;
  endif;
s = s+1;
endo;

  y = qint[6:ns1,1];
  x = infgap[6:ns1,1]~gdpghat[6:ns1,1];
  xlin = x~qint[5:ns1-1,1]~qint[4:ns1-2,1]~binfgap[6:ns1,1]~bgdpghat[6:ns1,1];
  nt = ns1 - 5;
  n = nt;
"";"10.a The test of nonlinearity for the Model 2 forward-looking model";"";
endif;


/* Alternative nonlinear specification: Model 2 in the backward-looking model */
if ksp == 10;
binf = zeros(nt,1); @ if gdpgap (t-1) > 0, binf = inf, otherwise binf = 0 @
bgdpgap = zeros(nt,1); @ if gdpgap (t-1) >0, bgdpgap = gdpgap, otherwise bgdpgap = 0 @

j = 2;
do until j>nt;
  if gdpgap[j-1,1]>0;
  binf[j,1] = inf[j,1];
  bgdpgap[j,1] = gdpgap[j,1];
  else;
  binf[j,1] = 0;
  bgdpgap[j,1] = 0;
  endif;

j = j + 1;
endo;

  y = qint[3:ns1,1];
  x = inf[2:ns1-1,1]~gdpgap[2:ns1-1,1];
  xlin = x~qint[2:ns1-1,1]~qint[1:ns1-2,1]~binf[2:ns1-1,1]~bgdpgap[2:ns1-1,1];
  nt = ns1 - 2;
  n = nt;
"";"10.b The test of nonlinearity for the Model 2 backward-looking model";"";
endif;


/* 11.a Alternative nonlinear specification: Model 3 in the forward-looking model */
if ksp == 11;
  y = qint[6:ns1,1];
  x = infgap[6:ns1,1]~gdpghat[6:ns1,1];
  xlin = x~qint[5:ns1-1,1]~qint[4:ns1-2,1]~infvar[6:ns1,1];
  nt = ns1 - 5;
  n = nt;
"";"11.a The test of nonlinearity for the Model 3 forward-looking model";"";
endif;


/* 11.b Alternative nonlinear specification: Model 3 in the backward-looking model */
if ksp == 12;
 y = qint[7:ns1,1];
  x = inf[6:ns1-1,1]~gdpgap[6:ns1-1,1];
  xlin = x~qint[6:ns1-1,1]~qint[5:ns1-2,1]~infvar[6:ns1-1,1];
  nt = ns1 - 6;
  n = nt;
"";"11.b The test of nonlinearity for the Model 3 backward-looking model";"";
endif;


/* 12.a Alternative nonlinear specification: Model 4 in the forward-looking model */
if ksp == 13;
infog = zeros(nt,1); @multiplication of expected inflation deviation and output gap @
/* infog[2:nt,1] = infgap[2:nt,1] .* gdpghat[1:nt-1,1]; */
infog = infgap .* gdpghat;

  y = qint[6:ns1,1];
  x = infgap[6:ns1,1]~gdpghat[6:ns1,1];
  xlin = x~qint[5:ns1-1,1]~qint[4:ns1-2,1]~infog[6:ns1,1];
  nt = ns1 - 5;
  n = nt;
"";"12.a The test of nonlinearity for the Model 4 forward-looking model";"";
endif;


/* 12.b Alternative nonlinear specification: Model 4 in the backward-looking model */
if ksp == 14;
infog = inf .* gdpgap;

  y = qint[3:ns1,1];
  x = inf[2:ns1-1,1]~gdpgap[2:ns1-1,1];
  xlin = x~qint[2:ns1-1,1]~qint[1:ns1-2,1]~infog[2:ns1-1,1];
  nt = ns1 - 2;
  n = nt;
"";"12.b The test of nonlinearity for the Model 4 backward-looking model";"";
endif;


/* 13.a Robust analysis for forward-looking model: W, SPF, CBO, Linear  (Table A.1) */
if ksp == 15;

  sinf = (ln(egdpdf[.,2]) -ln(egdpdf[.,1])) * 400;  
  sinf = zeros(nt-np,1)|sinf;
  sinfdv1 = sinf[1:ns1,1] - 4.24;
  sinfdv2 = sinf[ns1+1:nt,1] - 3.58;
  sinfdv = sinfdv1|sinfdv2;

  y = qint[nt-np+1:nt,1];
  x = sinfdv[nt-np+1:nt,1]~gdpghat[nt-np+1:nt,1];
  xlin =x~qint[nt-np:nt-1,1]~qint[nt-np-1:nt-2,1];
  nt = np;
  n = nt;
"";"13.a The test of nonlinearity: 68:IV - 00:IV, SPF, CBO, Linear";"";
endif;


/* 13.b Robust analysis for forward-looking model: 65:IV - 96:IV, Greenbook, CBO, Linear */
if ksp == 16;

gbinf = zeros(nt-ng-16,1)|gbinf[.,2]|zeros(16,1);
gbinfdv1 = gbinf[1:ns1,1] - 4.24;
gbinfdv2 = gbinf[ns1+1:nt,1] - 3.58;
gbinfdv = gbinfdv1|gbinfdv2;

y = qint[nt-ng-15:nt-16,1];
x = gbinfdv[nt-ng-15:nt-16,1]~gdpghat[nt-ng-15:nt-16,1];
xlin = x~qint[nt-ng-16:nt-17, 1]~qint[nt-ng-16-1:nt-17-1,1];
nt = ng;
n = nt;
"";"13.b The test of nonlinearity: 65:IV - 96:IV, Greenbook, CBO, Linear";"";
endif;


/* 13.c Robustness analysis for forward-looking model: 79:III - 00:IV, SPF, CBO, Linear */
if ksp == 17;

  y = qint[ns1+2:nt,1];
  x = sinfdv[ns1+2:nt,1]~gdpghat[ns1+2:nt,1];
  xlin =x~qint[ns1+1:nt-1,1]~qint[ns1:nt-2,1];
  nt = ns2-1;
  n = nt;
"";"13.c The test of nonlinearity: 79:III - 00:IV, SPF, CBO, Linear";"";
endif;


/* 13.d Robustness analysis for forward-looking model: 79:III - 96:IV, Greenbook, CBO, Linear */
if ksp == 18;

y = qint[ns1+2:nt-16,1];
x = gbinfdv[ns1+2:nt-16,1]~gdpghat[ns1+2:nt-16,1];
xlin = x~qint[ns1+1:nt-17,1]~qint[ns1:nt-17-1,1];
nt = ns2-17;
n = nt;
"";"13.d The test of nonlinearity: 79:III - 96:IV, Greenbook, CBO, Linear";"";
endif;


/* 13.e Robustness analysis for forward-looking model: 83:I - 00:IV, CBO, Linear */
if ksp == 19;

 y = qint[ns1+14+2:nt,1];
  x = infgap[ns1+14+2:nt,1]~gdpghat[ns1+14+2:nt,1];
  xlin =x~qint[ns1+14+1:nt-1,1]~qint[ns1+14:nt-2,1];
  nt = ns2-1-14;
  n = nt;
"";"13.e The test of nonlinearity: 83:I - 00:IV, CBO, Linear";"";
endif;


/* 13.f Robustness analysis for forward-looking model: 83:I - 00:IV, SPF, CBO, Linear */
if ksp == 20;

  y = qint[ns1+14+2:nt,1];
  x = sinfdv[ns1+14+2:nt,1]~gdpghat[ns1+14+2:nt,1];
  xlin =x~qint[ns1+14+1:nt-1,1]~qint[ns1+14:nt-2,1];
  nt = ns2-1-14;
  n = nt;
"";"13.f The test of nonlinearity: 83:I - 00:IV, SPF, CBO, Linear";"";
endif;


/* 14.a Robustness analysis for forward-looking model: W, CBO, Nonlinear */    
if ksp == 21;

  y = qint[6:nt,1];
  x =ninfgap[6:nt,1]~ngdpghat[6:nt,1]; 
  xlin = x~qint[5:nt-1,1]~qint[4:nt-2,1];
  nt = nt-5;
  n = nt;
"";"14. The test of nonlinearity: W, CBO, Nonlinear";"";
endif;


/* 14.b Robustness analysis for forward-looking model: Pre-Volcker, CBO, Nonlinear */
if ksp == 22;

  y = qint[6:ns1,1];
  x = ninfgap[6:ns1,1]~ngdpghat[6:ns1,1];
  xlin = x~qint[5:ns1-1,1]~qint[4:ns1-2,1];
  nt = ns1 - 5;
  n = nt;
"";"14.b The test of nonlinearity: pre-Volcker, CBO, Nonlinear"; "";
endif;


/*  14.c Robustness analysis for forward-looking model: Volcker-Greenspan, CBO, Nonlinear */
if ksp == 23;

  y = qint[ns1+2:nt,1];
  x = ninfgap[ns1+2:nt,1]~ngdpghat[ns1+2:nt,1];
  xlin =x~qint[ns1+1:nt-1,1]~qint[ns1:nt-2,1];
  nt = ns2-1;
  n = nt;
"";"14.c The test of nonlinearity: Volcker-Greenspan, CBO, Nonlinear"; "";
goto jumpN;
endif;

goto jumpN;

jumpR:
ksp = ksp +1;
endo;
endif;

if gg == 2;

do until khp > 7;
nt = 164;
 
/* 15.a Robustness analysis for forward-looking model: W, HP, Linear */

if khp == 1;
  y = qint[6:nt,1];
  x =infgap[6:nt,1]~gdpghat[6:nt,1]; 
  xlin = x~qint[5:nt-1,1]~qint[4:nt-2,1];
  nt = nt-5;
  n = nt;
"";"15.a The test of nonlinearity: W, HP, Linear";"";
endif;

/* 15.b Robustness analysis for forward-looking model: pre-Volcker, HP, Linear */

if khp == 2;
  y = qint[6:ns1,1];
  x = infgap[6:ns1,1]~gdpghat[6:ns1,1];
  xlin = x~qint[5:ns1-1,1]~qint[4:ns1-2,1];
  nt = ns1 - 5;
  n = nt;
"";"15.b The test of nonlinearity: pre-Volcker, HP, Linear"; "";
endif;


/* 15.c Robustness analysis for forward-looking model: Volcker-Greenspan, HP, Linear */

if khp == 3;
  y = qint[ns1+2:nt,1];
  x = infgap[ns1+2:nt,1]~gdpghat[ns1+2:nt,1];
  xlin =x~qint[ns1+1:nt-1,1]~qint[ns1:nt-2,1];
  nt = ns2-1;
  n = nt;
"";"15.c The test of nonlinearity: Volcker-Greenspan, HP, Linear"; "";
endif;

/* 15.d Robustness analysis for forward-looking model: 83:I - 00:IV, HP, Linear */

if khp == 4;
 y = qint[ns1+14+2:nt,1];
  x = infgap[ns1+14+2:nt,1]~gdpghat[ns1+14+2:nt,1];
  xlin =x~qint[ns1+14+1:nt-1,1]~qint[ns1+14:nt-2,1];
  nt = ns2-1-14;
  n = nt;
"";"15.d The test of nonlinearity: 83:I - 00:IV, HP, Linear";"";
endif;


/* 16.a Robustness analysis for forward-looking model: W, HP, Nonlinear */    
if khp == 5;

  y = qint[6:nt,1];
  x =ninfgap[6:nt,1]~ngdpghat[6:nt,1]; 
  xlin = x~qint[5:nt-1,1]~qint[4:nt-2,1];
  nt = nt-5;
  n = nt;
"";"16.a The test of nonlinearity: W, HP, Nonlinear";"";
endif;


/* 16.b Robustness analysis for forward-looking model: Pre-Volcker, HP, Nonlinear */
if khp == 6;

  y = qint[6:ns1,1];
  x = ninfgap[6:ns1,1]~ngdpghat[6:ns1,1];
  xlin = x~qint[5:ns1-1,1]~qint[4:ns1-2,1];
  nt = ns1 - 5;
  n = nt;
"";"16.b The test of nonlinearity: pre-Volcker, HP, Nonlinear"; "";
endif;


/*  16.c Robustness analysis for forward-looking model: Volcker-Greenspan, HP, Nonlinear */
if khp == 7;

  y = qint[ns1+2:nt,1];
  x = ninfgap[ns1+2:nt,1]~ngdpghat[ns1+2:nt,1];
  xlin =x~qint[ns1+1:nt-1,1]~qint[ns1:nt-2,1];
  nt = ns2-1;
  n = nt;
"";"16.c The test of nonlinearity: Volcker-Greenspan, HP, Nonlinear"; "";
goto jumpN;
endif;

goto jumpN;

jumpH:
khp = khp + 1;
endo;
endif;


jumpN:
rndseed 9137841;   @ resets random number generator so that identical sample is
                                     used each time @


@ set parameters that describe the data  @
    k = cols(x);                @ k is the number of nonlinear variables @
    klin = 1+cols(xlin);         @ klin is the total number of variables, nonlin
                                               ear, linear and constant term @
    xwhole = ones(n,1)~xlin;   @ xwhole is (n x klin) @




/* ===========================================================
             CALCULATE AND REPORT SOME BASIC STATISTICS
=============================================================*/
xbar = meanc(x);
sigx = sqrt(meanc((x - xbar')^2));

 
xlinbar = meanc(xlin);
siglinx = sqrt(meanc((xlin - xlinbar')^2));
ybar = meanc(y);
sigy = sqrt(meanc((y-ybar)^2));

/* **** This is optional for basic statistics ***

"***** Basic statistics******";
"number of observations";;n;
"means of nonlinear explanatory variables";xbar';
"standard deviations";sigx';
"means of all explanatory variables";xlinbar';
"standard deviations";siglinx';
"mean and standard deviation of dependent variable is";
ybar;;sigy;
*/


xx0 = xwhole'*xwhole;
xx0inv = invpd(xx0);

/* ===========================================================
             SET INITIAL VALUES FOR GLOBAL VARIABLES
==============================================================*/
 kqopt = 2;
          @ kqopt = 1 means evaluate covariance by iterating as in
                      Theorem 2.2 in Hamilton (2001)
               kqopt = 2 means evaluate covariance directly from Table 1 in Hamilton (2001)
               option 2 is faster but only works for k <= 5 @

   kc = 2;
          @ kc = 2 echos parameter values when proc is evaluated
            kc =1 produces no echo @
    gamx = ones(k,1);
          @ gamx can be used to restrict some of the weighting coefficients
            to be zero, if desired @

   ks = 0;
          @ ks = # of smoothed inferences desired
               ks = 0 means only evaluate likelihood function @
   xs = 0;
          @ xs will be a (ks x k) matrix of values for the vector x at which
            mean is to be evaluated for smoothed inference @
  xswhole = 0;
          @ xswhole will be a (ks x klin) matrix for all explanatory variables including
               constant term at which mean is to be evaluated for smoothed inference @
 _pdate = "";

/* ===========================================================
             INCLUDE NEEDED PROCEDURES
=============================================================*/
ll = 0;
proc(2) = lsq(yq,x1);
   @ This proc performs an OLS regression of yq on x1
        and puts value of log likelihood in the global scalar ll @
local b,eps,sigols,sigmle,ss,nq;
  b = invpd(x1'*x1)*x1'*yq;
   eps = yq - x1*b;
  sigols = sumc(eps^2)/(rows(x1)-cols(x1));
   sigmle = sumc(eps^2)/rows(x1);
   ss = sigols*invpd(x1'*x1);
   ll = -(n/2)*(1 + ln(2*pi)) - (n/2)*ln(sigmle);

/*  ** This is optional: Estimation results for OLS ***

  ""; "OLS regression results";
    ""; "ols coefficients";b';
     "ols see";;sqrt(sigols);
    "mle see";;sqrt(sigmle);
    "standard errors";sqrt(diag(ss))';
    "ols log likelihood";; ll;"";
*/
 
retp(b,sigmle^.5);
endp;

 {bhat,sigmle} = lsq(y,xwhole);
ll0 = ll;        @ this saves ll0 for use in adjusting f(y,theta) by scale of f(y) @

#include proccov;
#include procs;
 #include fullproc;


proc (0) = graph1dim(nofx,sigmult,xfix);
     @ this proc fills the (ks x nk) matrix xs and the (ks x klin) matrix xswhole
          with values needed to calculate the effect of changing variable nofx with
          all others fixed at xfix. The variable nofx is varied from its value in xfix plus or minus
           sigmult times its standard deviation @
      ks = 61;   @ ks is the number of function evaluations to be performed @
      xs = ones(ks, klin - 1) .* xfix';
      xs[.,nofx]=seqa(xfix[nofx,1]-sigmult*sigx[nofx,1],
(2*sigmult*sigx[nofx,1])/(ks-1),ks);
      xswhole = ones(ks,1) ~ xs;
      xs = xs[.,1:k];
endp;


/* ===========================================================
             PERFORM OLS REGRESSION AND TEST FOR NONLINEARITY
=============================================================*/


 {bhat,sigmle} = lsq(y,xwhole);
"";"Testing the null hypothesis of linearity with respect to x";
    "Note-- it is maintained under both null and alternative that model ";
   "is linear with respect to elements of xlin other than x";
ehat = y - xwhole*bhat;
zeta = lm2(ehat,xlin,x);

if gg == 1;
if ksp == 2;
   goto jumpE;
elseif ksp == 5;
   goto jumpE;
elseif ksp == 23;
   goto jumpHP;
else;
  goto jumpR;
endif;
endif;

if gg == 2;
   if khp < 7;
   goto jumpH;
    else;
   goto jumpF;
   endif;
endif;

jumpE:
/* ============================================================
               PERFORM IMPORTANCE SAMPLING, IF DESIRED
=============================================================*/

/* ============================================================
              SET INITIAL VALUES FOR PARAMETERS 
   ============================================================ */
kc = 1;
thx = ( 1.5 ./(sigx*sqrt(k)) ) | 1.5;   h = eye(k+1); i = 1; psi = zeros(1,k+2);

@ ---------------------- parameters of prior for theta ------------------------------------------ @

meta = 0;                         @ meta is mean of log of eta @
seta = 1.0;                       @ seta is std deviation of log of eta @
mg = ln(1./(sigx*sqrt(k)));  @ mg is k x 1 vector of prior means for ln(g) @
taug = 1.0*ones(k,1);          @ taug is prior std. deviation for ln(g) @
mth = mg | meta;
sigth = taug | seta;


@ ---------------------- parameters of prior for psi ------------------------------------------------ @
nsig = 0.25;                         @ prior is (1/sigma^2) ~ gamma(nsig, lamsig) @
lamsig = nsig*0.5*(sigy^2); 
hbet = n;     
mbet = zeros(klin,1); 
mbet[1,1] = meanc(y);

      @ prior is beta ~ N(mbet,hbet*sigma^2*invpd(xwhole'*xwhole))  @


@ ----------parameters that determine importance sampling density -------------- @
montdf = 2;                  @ montdf is degrees of freedom for student t 
                                         generated importance  density @
montfact = sqrt(2);                  @ montfact is factor by which standard deviations are
                                                    increased to obtain std. deviation of importance density @
pprob = 0.5;          @ pprob = probability of drawing from the Student t versus
                                  the spread-out prior  @

"";"prior distributions:";
"    ln(eta) ~ Normal(";;meta;;",";;seta;"^2)";
ii = 1;
do until ii > k;
"    ln(g(";;ii;;")) ~ Normal(";;mg[ii,1];;",";;taug[ii,1];;"^2)";
ii = ii+1;
endo;
"    (1/sigma^2) | eta ~ Gamma(";;nsig;;",";; lamsig;;")";
"    beta | sigma,theta ~ N(mbet,hbet*sigma*invpd(xwhole'*xwhole)) ";
"    mbet:";;mbet';
"    hbet:";;hbet;
"";

"Importance density:";
"    degreees of freedom of t distribution";;montdf;
"    fraction of observations from t distribution";;pprob;
"    factor by which std. deviation of importance density exceeds prior";;montfact;

@ ----------------------- parameters to control monte carlo runs -----------------------@

nmonte = 10000;         @ nmonte is number of monte carlo draws generated @
"Number of monte carlo draws";;nmonte;
"";

   thmle = abs(thx);
   pmix = h[1:k+1,1:k+1];

kmle = 2;
pmix = pmix*montfact^2;

uxmix = zeros(nmonte,1);    @uxmix can be used to keep track of
                                                 which component of importance density was used @

@ --------  calculation of constant terms for importance density ------------------- @

tprec = invpd(pmix);
tdet = detl;
tc = gamma( (montdf+k+1)/2 )/gamma(montdf/2);
tc = tc / (   sqrt(tdet) * (montdf * 3.14159)^( (k+1) / 2)  );
nc =1./( sqrt(2*3.14159).*sigth);   @ note that nc is (k +1) x 1 vector @
lnnc =ln(nc);


pmix = chol(pmix);



/* =============================================================
             INCLUDE NECESSARY PROCEDURES
   ============================================================= */

psi = 0; i = 0;                        @ needed to avoid tripping GAUSS error compiling code @
#include bayproc2;

proc normgam(sigtry,bettry,ngam,lamgam,betsy,varsy);
    @ this proc evaluates the log of the product of a gamma(ngam,lamgam) density
     for (1/sigtry) and a N(betsy,sigtry*varsy) density for bettry at the
     points sigtry and bettry @
	local f1,f2,m1,m2;
        if ngam > 10;
     	    f1 = ngam*ln(lamgam) - (ngam - 1)*ln(sigtry) - (lamgam/sigtry) - lnfact(ngam-1);
        else;
           f1 = ngam*ln(lamgam) - (ngam - 1)*ln(sigtry) - (lamgam/sigtry) - ln(gamma(ngam));
        endif;
	m1 = invpd(varsy);
	m2 = detl;
	f2 = (-klin/2)*ln(2*3.1415927*sigtry) -(1/2)*ln(m2);
        f2 = f2 - (1/(2*sigtry))*(bettry-betsy)'*m1*(bettry-betsy);
retp(f1 + f2);
endp;

proc priadj(th);
     @ this proc adds log of prior p(theta) to log of f(y|X,theta) to 
          arrive at log of f(y,theta|X) @
local q;
if ndpchk(16);
       "underflow before calling priadj";
endif;
   q = -((ln(th) - mth)^2)./(2*(sigth^2));
   q = q + lnnc - ln(th);
   q = sumc(q);
if kc > 2;
      "log of prior is";;q;
endif;
q = q + baby(th);  
if ndpchk(16);
   "underflow after calling priadj";
endif;
retp(q);
endp;   


proc stut(nstu,ndif);
      @ this proc generates a (1 x nstu) vector student t with ndf degrees of freedom @
       local stuf,stux;
       stuf = rndn(1,nstu);
       stux = rndn(ndif,1);
       stux  = sumc(stux^2)/ndif;
        stux = sqrt(stux);
       stuf = stuf/stux;
retp(stuf);
endp;

proc mix(i);
      @ this proc generates mixture of prior and MLE-weighted student t variable 
    global:
        thmle = (k+1) x 1 vector of ML estimates
	pmix = (k+1) x (k+1) matrix of cholesky decomposition of montfact^2 times
                     asymptotic  variance-covariance matrix 
        pprob = probability of drawing from the Student t versus the spread-out prior 
     output:
         prmix = (k+1) x 1 vector of variables generated from mixture of spread-out
                       Student t and prior @
local prmix,umix;
         
        umix = rndu(1,1);
        
         if umix < pprob;
              uxmix[i,1] = 1;
              prmix = pmix'*stut(k+1,montdf)' + thmle; 
         else;
              uxmix[i,1] = 0;
              prmix = mth + montfact*sigth.*rndn(k+1,1);
              prmix = exp(prmix);
        endif;
retp(prmix);
endp;

proc impor(thx);
      @ this proc calculates the value of the importance sampling density
           at the point thx @
local val1, val2,val;
    if ndpchk(16);
         "underflow before calling impor";
    endif;
    val1 = - ((ln(thx) - mth)^2) ./ (2 * ((montfact*sigth)^2) );
    val1 = val1 - ln(thx) + lnnc - ln(montfact);
    val1 = sumc(val1);
    val1 = exp(val1);
    if ndpchk(16);
          "underflow after calculating val1";
    endif;
    val2 = (thx - thmle)'*tprec*(thx - thmle); 
    val2 = 1 + val2/montdf; 
    val2 = tc*val2^( -(k+1+montdf)/2 );
    if ndpchk(16);
           "underflow after calculating val2";
    endif;
    val = pprob*val2 + (1 - pprob)*val1;  
    if ndpchk(16);
          "underflow after calling impor";
          "theta is";thx';
    endif;
    if kc > 2;
         "contribution of lognormal component to log importance density";;val1;
         "contribution of student t component to log importance density";;val2;
   endif;
retp(val);
endp;

thet = zeros(nmonte,k+1);
psi = zeros(nmonte,klin+1);

wtchk = zeros(nmonte,2);
thwt = ones(nmonte,1);


i = 1;
do until i > nmonte;
    tryagain:
           if ndpchk(16);
                    "underflow occurred prior to calling mix";
                    ndpclex;
              endif;
    thet[i,.] = mix(i)';
    if ndpchk(16);
                    "underflow occurred just after calling mix";
                    ndpclex;
              endif;

    if minc(thet[i,.]') < 0;
          goto tryagain;
    endif;

    beep1 = priadj(thet[i,.]') - ll0;
     if ndpchk(16);
                    "underflow occurred just after calling priadj";
                    "beep1 is";;beep1;
                    ndpclex;
              endif;
      beep2 = impor(thet[i,.]');
       if ndpchk(16);
                    "underflow occurred just after calling impor";
                    "beep2 is";;beep2;
                    ndpclex;
              endif;
     @ control for underflows @
      if beep1 < -500;
              thwt[i,1] = 0;
      else;
             thwt[i,1] = exp(beep1 - ln(beep2)  );
             wtchk[i,1] = exp(beep1);
             wtchk[i,2] = beep2;
 
        endif;
    
       if ndpchk(16);
                    "underflow occurred right after exp and ln";
                    "beep1 is";;beep1;
                    "beep2 is";;beep2;
                    ndpclex;
              endif;
i = i + 1;
endo;

if ndpchk(16);
    "underflow occurred prior to tabulating monte carlo";
    ndpclex;
endif;

nwt = sumc(thwt);
"sum of weights for Monte Carlo Draws is";;nwt;
"If this is small, there may be a numerical problem with the simulation";

if ksp == 2;
"";
"Bayesian Posterior distribution for pre-Volcker period
in the forward-looking model";
"";
endif;

if ksp == 5;
"";
"Bayesian Posterior distribution for pre-Volcker period in the
backward-looking model";
"";
endif;

" estimated mean for theta parameters";
thm = sumc (thet .* thwt);
thm = thm/nwt;
thm';
"estimated standard errors";
thv = (thet - thm')'*( (thet - thm') .* thwt) ;
thv = diag(thv/nwt);
sqrt(thv)';
"standard error of estimated mean";
thu = ( (thet - thm') .* thwt )'*( (thet - thm') .* thwt );
thu = diag(thu);
thu = thu ./ (  (sumc(thwt))^2 );
sqrt(thu)';
"Geweke's measure of relative efficiency";
thv'./(nmonte * thu)';

"";" estimated mean for psi parameters";
psim = sumc (psi .* thwt);
psim = psim/nwt;
psim';
"estimated standard errors";
psiv = (psi - psim')'*( (psi - psim') .* thwt) ;
psiv = diag(psiv/nwt);
sqrt(psiv)';
"standard error of estimated mean";
psiu = ( (psi - psim') .* thwt )'*( (psi - psim') .* thwt );
psiu = diag(psiu);
psiu = psiu ./ (  (sumc(thwt))^2 )';
sqrt(psiu)';
"Geweke's measure of relative efficiency";
psiv'./(nmonte * psiu)';


hchk = thwt~wtchk~thet~seqa(1,1,nmonte);
hchk = sortc(hchk,1);
hchk[.,1] = hchk[.,1]/nwt;
hchk[.,2] = hchk[.,2]/sumc(hchk[.,2]);
hchk[.,3] = hchk[.,3]/sumc(hchk[.,3]);
"";"Fraction of distribution accounted for by:";
"          Most influential observation";;hchk[nmonte,1];
"          50 most influential observations";;sumc(hchk[nmonte-49:nmonte,1]);
"";"Fifty most influential observations are as follows";
"weight   f(y,thet)   I(thet)   thet  # in simulation";
format 12,4;
hchk[nmonte-49:nmonte,.];
format 16,8;

if ndpchk(16);
    "underflow occurred as a result of tabulating monte carlo";
    ndpclex;
endif;


@ free up some memory space @
clear hchk, qz*,uxmix,wtchk,xham,xlee1,xmork,xzham,xzmork,xzwhole,_op*;

/* ===========================================================
                GRAPH FUNCTIONS OF INTEREST
  ============================================================*/
sigstep = 2;     @ sigstep is the multiple of standard deviations used in graphing
                             inferred function @
critsig = 0.05;   @ call to proc seesmooth will calculate (1 - critsig)*100 percent
                              confidence intervals @




proc(3) = seesmooth(critsig);
@ this proc generates smoothed inferences and 95% confidence intervals for the
function evaluated at the points contained in the global ks x k matrix xs @
local i, j, itest, isum, cjunk, chis, chierr, chisavg, xlow, xhigh;
chis = zeros(ks,nmonte);   @ col i contains smoothed estimates for generated 
                                               parameter from monte carlo run i @
chierr = zeros(ks,nmonte); @ col i contains smoothed estimates for generated
                                                parameter from monte carlo run i plus measurement 
                                                inference noise @

i = 1;
do until i > nmonte;
     cjunk = full( (thet[i,.] ~ psi[i,.])');
      chis[.,i] = cjunk[.,1];
      chierr[.,i] = chis[.,i] + sqrt(cjunk[.,2]).*rndn(ks,1);
      if ndpchk(16);
               "underflow occurred analyzing realization # ";;i;
               "theta and psi vectors";
               thet[i,.];
               psi[i,.];
              ndpclex;
     endif;
i = i+1;
endo;
chisavg = (chis*thwt)/nwt;

xlow = zeros(ks,1);
xhigh = zeros(ks,1);
j = 1;
do until j > ks;
   cjunk = sortc( (chierr[j,.]' ~ thwt) ,1);
    itest = 1;
    isum = 0;
    start1:
     if (isum/nwt) < (critsig/2);
           isum = isum + cjunk[itest,2];
           itest = itest + 1;
           goto start1;
     endif;  
   xlow[j,1] = cjunk[itest,1];
   itest = nmonte;
   isum = 0;
   start2:
   if (isum/nwt) < (critsig/2);
           isum = isum + cjunk[itest,2];
           itest = itest - 1;
           goto start2;
   endif;
   xhigh[j,1] = cjunk[itest,1];
j = j+1;
endo;
retp(chisavg,xlow,xhigh);
endp;



/*--------------------------- GRAPH EFFECTS OF VARIABLES #1 AND #2 ------------------------*/


ks = 61;


/* Graphical inference for the pre-Volcker period if there is nonlinearity */

if ksp == 2;
call graph1dim(1,sigstep,xlinbar);  @ this sets xs so that variable 1 changes 
                                                        with variable 2,3 fixed @
{chisavg,xlow,xhigh} = seesmooth(critsig);

"";
"4.b Effect of inflation deviation on the interest rate: S1, CBO, FL";"";
"xs~u(x)~xlow~xhigh";
s1einf = xs[.,1]~chisavg~xlow~xhigh;
s1einf; " ";

let _pltype[3,1] = 6 3 3;
_pgrid = 3|0;
_pcolor = 0;
title("Figure 1a. The effect of the inflation deviation on the interest rate:
forward-looking model");
_ptek = "s1fcinf.tkf";
xlabel("forecast inflation deviation from target");
ylabel("interest rate");
xy(xs[.,1],chisavg~xlow~xhigh);

call graph1dim(2,sigstep,xlinbar);  @ this sets xs so that variable 2 changes 
                                                        with variable 1,3 fixed @
{chisavg,xlow,xhigh} = seesmooth(critsig);

"";
"4.c Effect of output gap on the interest rate: S1, CBO, FL";"";
"xs~u(x)~xlow~xhigh";
s1egp = xs[.,2]~chisavg~xlow~xhigh;
s1egp; "";

let _pltype[3,1] = 6 3 3;
_pgrid = 3|0;
_pcolor = 0;
title("Figure 2a. The effect of output gap on the interest rate:
forward-looking model");
_ptek = "s1cfgp.tkf";
xlabel("forecast output gap");
ylabel("interest rate");
xy(xs[.,2],chisavg~xlow~xhigh);

goto jumpR;
endif;


/* Graphic inference for the pre-Volcker period the backward-looking model */

if ksp == 5;
call graph1dim(1,sigstep,xlinbar);  @ this sets xs so that variable 1 changes 
                                                        with variable 2,3 fixed @
{chisavg,xlow,xhigh} = seesmooth(critsig);

"";"7.b Effect of inflation on the interest rate: S1, CBO, BL";"";
"xs~u(x)~xlow~xhigh";
winf = xs[.,1]~chisavg~xlow~xhigh;
winf; " ";

let _pltype[3,1] = 6 3 3;
_pgrid = 3|0;
_pcolor = 0;
title("Figure 1b. The effect of the inflation on the interest rate:
backward-looking model");
_ptek = "s1bcinf.tkf";
xlabel("Inflation");
ylabel("interest rate");
xy(xs[.,1],chisavg~xlow~xhigh);

call graph1dim(2,sigstep,xlinbar);  @ this sets xs so that variable 2 changes 
                                                        with variable 1,3 fixed @
{chisavg,xlow,xhigh} = seesmooth(critsig);

"";"7.c Effect of output gap on the interest rate: S1, CBO, BL";"";
"xs~u(x)~xlow~xhigh";
wgp = xs[.,2]~chisavg~xlow~xhigh;
wgp; "";

let _pltype[3,1] = 6 3 3;
_pgrid = 3|0;
_pcolor = 0;
title("Figure 2b. The effect of output gap on the interest rate:
backward-looking model");
_ptek = "s1cbgp.tkf";
xlabel("Output gap");
ylabel("Interest rate");
xy(xs[.,2],chisavg~xlow~xhigh);

goto jumpR;
endif;

jumpHP:
gg = gg +1;
endo;

jumpF:
end;
