@ ------------------------------- Test_1.g ------------------------------------
"
    28 December 2010
    Alfred Maußner

    Solve the benchmark business cycle model of Heer and Maußner (2009),
    Section 1.5.1 with the help of the SDRAM program.
    
    The user must input the matrices of the log-linear version of the model.
"
------------------------------------------------------------------------------- @

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

/* Choice of solution method */
_equations=0;   @ "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=1;      @ "if =1 only linear approximations of the models equations are computed, note that if _equations=0 only linear solutions 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=0; @ "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=24000;       @ "the number of elements in each simulated time series"     @
nobs1=20;      @ "the length of the impulse reponsees"                      @
nofs=1;      @ "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="Benchmark_1b.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:=[k]                          "@
_nz=1;  @ "the number of shocks, here:  z:=[Z]                          "@
_ny=8;  @ "the number of non predetermined variables, here: y:=[y, c, i, r, w, n, lambda,p]  "@
_nu=6;  @ "if _GSchur=0 you must tell the program the number of static equations _nu. If _equations=0 the program assumes that the last _ny-_nu variables in y are costates" @
_ns=1;  @ "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.
**
*/

Var[1].varname="Output";
Var[1].vartype="y";
Var[1].varpos=1;
Var[1].varprint=1;
Var[1].crosscorr=1;
Var[1].varplot=1;
Var[1].plotno=1;
Var[1].relsx=1;

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="Investment";
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="Hours";
Var[4].vartype="y"; 
Var[4].varpos=4;  
Var[4].varprint=1;  
Var[4].crosscorr=0; 
Var[4].varplot=1;   
Var[4].plotno=4;    

Var[5].varname="Real Wage";
Var[5].vartype="y"; 
Var[5].varpos=5;   
Var[5].varprint=1;  
Var[5].crosscorr=1; 
Var[5].varplot=1;   
Var[5].plotno=3;    

Var[7].varname="Bond Price";
Var[7].vartype="y";
Var[7].varpos=8;
Var[7].varprint=1;
Var[7].crosscorr=0;
Var[7].varplot=1;
Var[7].plotno=3;

Var[8].varname="User Costs of Capital";
Var[8].vartype="y";
Var[8].varpos=6;
Var[8].varprint=1;
Var[8].crosscorr=0;
Var[8].varplot=1;
Var[8].plotno=3;
    
Var[9].varname="Capital Stock";
Var[9].vartype="x";
Var[9].varpos=1;
Var[9].varprint=0;
Var[9].crosscorr=0;
Var[9].varplot=1;
Var[9].plotno=4;

Var[10].varname="TFP Shock";
Var[10].vartype="z";
Var[10].varpos=1;
Var[10].varprint=0;
Var[10].crosscorr=0;
Var[10].varplot=1;
Var[10].plotno=1;

@ Third Part @

/* Set legend positions individually */
_plegend[1,1,1]=10;
_plegend[1,1,2]=0.9;

_plegend[1,2,1]=10;
_plegend[1,2,2]=3.5;

_plegend[1,3,1]=9;
_plegend[1,3,2]=0.9;

_plegend[1,4,1]=6;
_plegend[1,4,2]=0.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, if _equation=1, or else input the coefficients of the matrices.
**
** 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 @
a=1.005;
alpha=0.27;
beta=0.994;
eta=2.0;
delta=0.011;
rhoZ=0.90;
sigmaz=0.0072;
nstar=0.13;

@ Second Part @
yk=(a^eta-beta*(1-delta))/(beta*alpha);
ck=yk+(1-a-delta);
theta = (1-alpha)*(yk/ck)*(1-nstar)*(1/nstar);

/* If _equations=0 input the matrices here. Note, the equations numbers refer to the CoRRAM manual */
/* Equation 3.4.a */
 Cu[1,2]=-eta;
 Cu[1,4]=-theta*(1-eta)*(nstar/(1-nstar));
Cxl[1,2]=1;

/* Equation 3.4.b */
 Cu[2,2]=1-eta;
 Cu[2,4]=-(theta*(1-eta)-1)*(nstar/(1-nstar));
 Cu[2,5]=-1;
Cxl[2,2]=1;

/* Equation 3.4.c */
 Cu[3,1]=-1;
 Cu[3,6]=1;
Cxl[3,1]=1;


/* Equation 3.4.d */
 Cu[4,1]=-1;
 Cu[4,4]=1;
 Cu[4,5]=1;

/* Equation 3.4.e */
 Cu[5,1]=1;
 Cu[5,4]=alpha-1;
Cxl[5,1]=alpha;
 Cz[5,1]=1;

/* Equation 3.4.f */
 Cu[6,3]=1;
 Cu[6,1]=-(a-1+delta)/yk;
 Cu[6,2]=-(ck/yk);

/* Equation 3.4.g */
Dxl[1,1]=a;
Fxl[1,1]=delta-1;
 Fu[1,3]=delta+a-1;

/* Equation 3.4.h */
Dxl[2,2]=1;
Fxl[2,2]=-1;
 Du[2,4]=1-beta*(a^-eta)*(1-delta);

/* Transition equation for shock */
_Rho[1,1]=RhoZ;
_Sigma[1,1]=1;
_omega[1,1]=SigmaZ;


/* You can skip this part, if you input the matrices.
** Otherwise, 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)
*/

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

proc(1)=Sys(w);

  local fx;
  fx=zeros(_nx+_ny,1);

  if _eqno==0; retp(fx); else; retp(fx[_eqno]); endif;
  retp(fx);

endp;


/* Transition equation for shock */
_Rho[1,1]=RhoZ;
_Sigma=SigmaZ;
_Omega=eye(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: */
/* According to the numbering, lambda is the 7th variable in the vector y */
Lsx=Lyx[7,.]*(Lxx-eye(_nx));
Lsz=Lyx[7,.]*Lxz+Lyz[7,.]*(_Rho-Eye(_nz));


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

