# Deterministic endval and initval

**URL:** https://forum.dynare.org/t/deterministic-endval-and-initval/3685
**Category:** Dynare help (legacy posts)
**Created:** [11 February 2014 00:56 UTC](https://forum.dynare.org/t/deterministic-endval-and-initval/3685 "2014-02-11T00:56:09Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![lonechicken](https://forum.dynare.org/letter_avatar_proxy/v4/letter/l/b38774/32.png) [@lonechicken](https://forum.dynare.org/u/lonechicken)
#### Post date: [11 February 2014 00:56 UTC](https://forum.dynare.org/t/deterministic-endval-and-initval/3685/1 "2014-02-11T00:56:09Z")

</div>

I have a linear model that I would like to run with initial and terminal conditions; in particular the variable “gap”. I mainly care about keeping “gap” at the values I define in initval and endval at the beginning and end of the simulation. Running the code below does this, but it does not move smoothly to gap’s terminal value- it appears to move towards the steady state and then just jump to the terminal value I chose in the last quarter of the simulation, as if the model does not even take the terminal condition into consideration while it is running, until the last quarter, when it suddenly jumps to that value. Any way to make it so that my endval value for gap functions as a real terminal condition that the model appears to actually take into consideration? (Hope that makes sense).

[code]var infl infl\_four zgap\_ zgap zrrl qgap gap rate;

model(linear);  
gap=gap(-1)+(1-1.1906+0.3067)_(qgap(-1)-gap(-1))+0.3067_(gap(-1)-gap(-2))+zgap;

infl=0.5_infl\_four(-1)+(1-0.5)infl(1)+0.02667gap(-1)+0.11268_(zrrl-zrrl(-1));  
qgap=-1.7602_zrrl+0.62_zgap\_+0.38_gap;  
zrrl=0.967_zrrl(1)+(1-0.967)_(rate-infl-0.6_gap);  
zgap=(1-1.1906+0.3067)_(qgap-qgap(-1))-0.3067_(1-1.1906+0.3067)_(0.98^2)_(qgap(1)-qgap)+1.1906_0.98_zgap(1)-0.3067\*(0.98^2)_zgap(2);  
zgap\_=0.93_zgap\_(1)+(1-0.93)_qgap;  
infl\_four=0.25_(infl+infl(-1)+infl(-2)+infl(-3));  
rate=max(0,0.85_rate(-1)+0.15_(0.0+infl+0.5\*(infl-0.02)+gap));  
end;

initval;  
gap=-0.04;  
infl=0.012;

infl\_four=0.012;  
rate=0.0012;  
end;

endval;  
gap=0.005;

infl=0.02;  
infl\_four=0.02;  
rate=0.04;

end;

simul(periods=40,maxit=400) ;  
[/code]

---

<div class="post-metadata">

### Author: ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)
#### Post date: [11 February 2014 19:53 UTC](https://forum.dynare.org/t/deterministic-endval-and-initval/3685/2 "2014-02-11T19:53:31Z")

</div>

This manual draft should answer your question:

[code]var c k;  
varexo x;  
@dots{}  
model;  
c + k - aa_x_k(-1)^alph - (1-delt)_k(-1);  
c^(-gam) - (1+bet)^(-1)_(aa_alph_x(+1)\*k^(alph-1) + 1 - delt)\*c(+1)^(-gam);  
end;

initval;  
c = 1.2;  
k = 12;  
x = 1;  
end;

endval;  
c = 2;  
k = 20;  
x = 1.1;  
end;  
simul(periods=200);  
[/code]  
In this example, the problem is finding the optimal path for consumption  
and capital for the periods t=1 to T=200, given the path of the exogenous  
technology level @code{x}. Setting @code{x=1.1} in the  
@code{endval}-block without a @code{shocks}-block implies that technology  
jumps to this new level in t=1 and stays there forever. Because the law  
of motion for capital is backward-looking, we also need an initial  
condition for @code{k} at time 0, specified in the @code{initval}-block.  
Similarly, because the Euler equation is forward-looking, we need a  
terminal condition for @code{c} at t=201, which is specified in the  
@code{endval}-block. Specifying @code{c} in the @code{initval}-block and  
@code{k} in the @code{endval}-block has no impact on the results: due to  
the optimization problem in the first period being to choose @code{c,k}  
at t=1 given predetermined capital stock @code{k} inherited from t=0 as  
well as the current and future values for technology, the value for  
@code{c} at time t=0 plays no role. The same applies to the choice of  
@code{c,k} at time t=200, which does not depend on @code{k} at t=201. As  
the Euler equation shows, that choice only depends on current capital as  
well as future consumption @code{c} and technology @code{x}, but not on  
future capital @code{k}. The intuitive reason is that those variables are  
the consequence of optimization problems taking place in at periods t=0  
and t=201, respectively, which are not considered. Thus, when specifying  
those values in the @code{initval} and @code{endval}-blocks, Dynare takes  
them as given and basically assumes that there were realizations  
of exogenous variables and states (basically initial/terminal conditions  
at the unspecified time periods t\<0 and t\>201) that make those choices  
equilibrium values.

This also suggest another way of looking at the use of @code{steady}  
after @code{initval} and @code{endval}. Instead of saying that the  
implicit unspecified conditions before and after the simulation range  
have to fit the initial/terminal conditions of the endogenous variables  
in those blocks, @code{steady} specifies that those conditions at t\<0 and  
t\>201 are equal to being at the steady state given the exogenous  
variables in the @code{initval} and @code{endval}-blocks and sets the  
endogenous variables at t=0 and t=201 to the corresponding steady state  
equilibrium values.

The fact that @code{c} at t=0 and @code{k} at t=201 specified in  
@code{initval} and @code{endval} are taken as given has an important  
implication for plotting the simulated vector for the endogenous  
variables: this vector will also contain the initial and terminal  
conditions and thus is 202 periods long in the example. When you specify  
arbitrary values for the initial and terminal conditions for forward- and  
backward-looking variables, respectively, these values can be very far  
away from the endogenously determined values at t=1 and t=200. While the  
values at t=0 and t=201 are unrelated to the dynamics for 0\<t\<201, they  
may result in strange-looking large jumps. In the example above,  
consumption will display a large jump from t=0 to t=1 and capital will  
jump from t=200 to t=201.
