@ ------------------------------- NKPC_1.g ------------------------------------
"
    09 Februry 2010
    Last revision: 23 February 2011
    Alfred Maußner

    Solve and simulate a simple New Keynesian Model with
    sticky prices. The model is taken from Walsh, Monetary
    Theory and Policy, Second Edition, MIT Press, 2003,
    p. 230ff. and desribed in more detail "The Analytics of New Keynesian
    Phillips Curves, University of Augsburg, Volkswirtschaftliche 
    Diskussionsreihe No. 313.
"
------------------------------------------------------------------------------- @

@ -------------------- Do not change the next two lines of code ---------------- @
new;                  @ clear memory @
library user, pgraph; @ load standard libraries @
@ ------------------------------------------------------------------------------ @

/* Choice of solution method */
_equations=1;   @ "if =1 you must input the equations of your model, if =0 you must input the coefficients of the matrices of your log-linearized model" @
_GSchur=0;      @ "if =1 the generalized Schur factorization will be used to compute the linear part of the solution" @
_linear=2;      @ "if =1 only linear approximations of the models equations are computed"    @

/* Choice of output */
_Moments=1;    @ "if _moments=0, no moments will be computed"               @
_IR=1;         @ "if _IR=0, no impulse responses will be computed"          @
_confidence=1; @ "if =1 confidence intervalls for the simulated moments will be printed " @

_HPL=1600;     @ "the filter weight of the Hodrick-Prescott filter"         @
               @ "if _HPL=0, the filter will not be applied"                @

nobs=80;       @ "the number of elements in each simulated time series"     @
nobs1=20;      @ "the length of the impulse reponsees"                      @
nofs=300;      @ "the number of simulations from which moment averages are to be computed" @

_scale=0;      @ "if _scale=1 all plots will have the same scale"           @
_nocolor=0;    @ "if=0, lines will be colored"                              @

/* Choice of random numbers */
_makeShocks=0; @ "if=1, an array of shocks will be created that can be used in repeated simulations"   @
_loadShocks=0; @ "if=1, the program looks for the file epsilon_array and loads shocks from this array" @
               @ "if=0, the program draws new random numbers for each simulation"                      @

/* Choice of output file */
outfile="NKPC_1.txt"; @ "the name of the file to which the program writes its output" @

/* Determine the type and number of the models variables */
_nx=1;    @ "the number of states, here:  x:=s[t-1]                          "@
_nz=2;    @ "the number of shocks, here:  z:=[Zhut, Vhut]                          "@
_ny=14;   @ "the number of not predetermined variables, here:  y=[y, c, n, ytilde, ntilde, pa, w, gtilde, pi, q, lambda, g1, g2,s]   "@
_nu=11;   @ "the number of static equations" @
_ns=0;    @ "if _equations=0 you may include futher variables s in the vector y and provide the respective matrices Lsx and Lsz. See the manual" @

@ ---------------------------------- Do not change the next line of code --------------------- @
#include CoRRAM_1.src;
@ -------------------------------------------------------------------------------------------- @

/*
**
** You must put in the names of all variables in your model
** for which you either want the program to compute and display
** impulse respones or compute and print second moments.
** 
** Thus, variables that are in x, y, or z, for which you do
** not provide informaion, are ignored when plotting impulse
** responses or when printing second moments.
**
**
** The order in which the variables appear below is also the
** order in which results will be printed.
**
** Note, that the number and types of variables depends on your choice of _GSchur !
*/
Var[1].varname="Output"; @ name of the variable that appears in plots and in tables @
Var[1].vartype="y";          @ indicate what type - x, y, or z - the variable has       @
Var[1].varpos=1;             @ inicate where in the vector the variable is located      @
Var[1].varprint=1;           @ if =1, second moments will be printed in a table         @
Var[1].crosscorr=1;          @ if =1, a colum with crosscorelations between this and the other variables will be printed @
Var[1].varplot=1;            @ if =1, the variables impulse response will be plotted    @
Var[1].plotno=1;             @ the graphics panel in which the impulse reponse appears. up to six different panels are supported @
Var[1].relsx=1;              @ if =1, a colum will be printed that shows the standard deviation of the other variables relative to this variable @

Var[2].varname="Consumption";
Var[2].vartype="y";
Var[2].varpos=2;
Var[2].varprint=1;
Var[2].crosscorr=0;
Var[2].varplot=1;
Var[2].plotno=2;

Var[3].varname="Hours";
Var[3].vartype="y";
Var[3].varpos=3;
Var[3].varprint=1;
Var[3].crosscorr=0;
Var[3].varplot=1;
Var[3].plotno=2;

Var[4].varname="Rate of Inflation";
Var[4].vartype="y";
Var[4].varpos=9;
Var[4].varprint=1;
Var[4].crosscorr=0;
Var[4].varplot=1;
Var[4].plotno=3;

Var[5].varname="Nominal Interest Rate";
Var[5].vartype="y";
Var[5].varpos=10;
Var[5].varprint=0;
Var[5].crosscorr=0;
Var[5].varplot=1;
Var[5].plotno=4;

Var[6].varname="TFP";
Var[6].vartype="z";
Var[6].varpos=1;
Var[6].varprint=0;
Var[6].crosscorr=0;
Var[6].varplot=0;
Var[6].plotno=1;
                     
Var[7].varname="Real Wage";
Var[7].vartype="y"; 
Var[7].varpos=7;   
Var[7].varprint=1;  
Var[7].crosscorr=1; 
Var[7].varplot=1;   
Var[7].plotno=3;    

Var[8].varname="Shock in Taylor Rule";
Var[8].vartype="z"; 
Var[8].varpos=2;  
Var[8].varprint=1;  
Var[8].crosscorr=0; 
Var[8].varplot=1;   
Var[8].plotno=4;    

Var[9].varname="Marginal Utility";
Var[9].vartype="y"; 
Var[9].varpos=12;  
Var[9].varprint=0;  
Var[9].crosscorr=0; 
Var[9].varplot=1;   
Var[9].plotno=5;  

    
  
/*
**
** First, you must insert the parameters of your model.
**
** Second, if _equation=1, you must compute the stationary solution
** of all variables in your model otherwise you must compute
** - if necessary - those quantities that appear the in matrices.
**
** Third, you must put the equations of your model in the
** proc SYS
**
** Fourth, you must stet up the matrices _Rho and _Omega and
** asign a value to _sigma (the parameters of the transition
** equation for the shocks).
*/

@ First Part @
alpha=0.27;
beta=0.994;
eta=2.0;
theta=0.5;
nstar=0.13;

epsilon=6;
phi=0.75;

rhoZ=0.90;
sigmaz=0.0072;

pistar=1.0167;
rhov=0.5;
sigmav=0.002;

delta=1.01;


@ Second Part @
zstar=0;
vstar=0;
gstar=(epsilon-1)/epsilon;
ystar=nstar^(1-alpha);
cstar=ystar;
pastar=1;
wstar=(1-alpha)*gstar*(ystar/nstar);
lambdastar=cstar^(-eta);
gamma2=gstar*(1-alpha)*(nstar^(-(alpha+eta*(1-alpha)+theta)));
qstar=pistar/beta;
g1star=(lambdastar*gstar*ystar)/(1-(beta*phi));
g2star=g1star/gstar;
sstar=1;
ntildestar=nstar;
ytildestar=ystar;


@ Third Part @

/* You must gather the stationary solutions of the variables
** in the following two vectors: (the _zstar vector is always the zero vector and the program adds this vector for you)
**
**
** "the vector _xstar collects the stationary values of the state variables" 
** "the vector _ystar collects the stationary values of the variables in the vector y" 
*/

_xstar=sstar;      @ 1    bzw. 18  @
_ystar=     ystar| @ 2    bzw. 19  @
            cstar| @ 3    bzw. 20  @
            nstar| @ 4    bzw. 21  @
       ytildestar| @ 5    bzw. 22  @
       ntildestar| @ 6    bzw. 23  @
           pastar| @ 7    bzw. 24  @
            wstar| @ 8    bzw. 25  @
            gstar| @ 9    bzw. 26  @
           pistar| @ 10   bzw. 27  @
            qstar| @ 11   bzw. 28  @
            sstar| @ 12   bsw. 29  @
       lambdastar| @ 13   bzw. 30  @
           g1star| @ 14   bzw. 31  @
           g2star; @ 15   bzw. 32  @;
              
_zstar=zstar|      @ 16   bzw. 33  @
       vstar;      @ 17   bzw. 34  @


/* Since the procedure Sys receives _wstar|_wstar, with
** _wstar=_xstar|_ystar|_zstar, where
** the second entry of _wstar indicates next period values,
** you must use this ordering of the variables in Sys. Also note that
** the line before the endp statement of Sys must contain the
** command:
** if _eqno==0; retp(fx); else; retp(fx[_eqno]); endif;
*/

@ Third Part: in Sys: specify the equations of your model @

proc(1)=Sys(w);
  local fx, z1, v1, na1, na2;
  
  z1=exp(w[16]);
  v1=exp(w[17]);

  fx=zeros(_nx+_ny,1);
  /* the 12 static equations: (4.7a)-(4.7l), where I condense (4.7j) and (4.7k) into one equation */
  @ (4.7a)  @
  fx[1]=(w[3]^(-eta))-w[13];   
  @ (4.7b)  @
  fx[2]=w[2]-w[3];
  @ (4.7c)  @
  fx[3]=(w[4]^theta)-(1/gamma2)*w[13]*w[8];
  @ (4.7d) @
  fx[4]=w[8]-(1-alpha)*w[9]*z1*(w[6]^(-alpha));
  @ (4.7e) @
  fx[5]=w[5]-z1*(w[6]^(1-alpha));
  @ (4.7f) @
  fx[6]=w[5]-w[12]*w[2];
  @ (4.7g) @
  fx[7]=1-(1-phi)*(w[7]^(1-epsilon))-phi*((pistar/w[10])^(1-epsilon));
  @ (4.7h) @  
  fx[8]=w[7]-(epsilon/(epsilon-1))*(w[14]/w[15]);  
  @ (4.7i) @
  fx[9]=(w[11]/qstar)-((w[10]/pistar)^delta)*v1;  
  @ (4.7j) and (4.7k) @
  na1=(w[7]^(-epsilon))*(w[2]/z1);
  na2=na1^(1/(1-alpha));
  fx[10]=(w[6]^(1-alpha))-(1-phi)*na1-phi*(((w[4]/phi)-((1-phi)/phi)*na2)^(1-alpha));
  @ (4.7l) @
  fx[11]=w[12]-(1-phi)*(w[7]^(-epsilon))-phi*((w[10]/pistar)^epsilon)*w[1];
  
  /* The 4 dynamic equations (4.8a)-(4.8d) */
  @ (4.8a) @
  fx[12]=w[18]-w[12];
  @ (4.8b) @
  fx[13]=w[13]-beta*w[11]*(w[30]/w[27]);
  @ (4.8c) @
  fx[14]=w[14]-w[13]*w[9]*(w[2]^(1/(1-alpha)))*(w[5]^(-alpha/(1-alpha)))*(w[7]^(-epsilon/(1-alpha)))
        -beta*phi*(((pistar*w[7])/(w[27]*w[24]))^(-epsilon/(1-alpha)))*w[31];
  @ (4.8d) @
  fx[15]=w[15]-w[13]*w[2]*(w[7]^(-epsilon))-beta*phi*((pistar/w[27])^(1-epsilon))*((w[7]/w[24])^(-epsilon))*w[32];
  
  if _eqno==0; retp(fx); else; retp(fx[_eqno]); endif;

endp;

/* Fourth Part: Transition equation for shock */
_Rho[1,1]=RhoZ;
_Rho[2,2]=RhoV;
_Omega=eye(_nz);
_Omega[1,1]=SigmaZ;
_Omega[2,2]=SigmaV;
_Sigma=1;


@ -------------- Do not change the next line of code ------------- @
#include CoRRAM_2.src;
@ ----------------------------------------------------------------- @

/* if you model includes additional variables, _ns>0, you must input Lsx and Lsz here: */
Lsx=0;
Lsz=0;

@ -------------- Do not change the remaining lines of code ------------ @
#include CoRRAM_3.src;

ende:
end;
@ ----------------------------------------------------------------------- @
