From f94d4e91f39aea5c2cf3e26e1a0d5e48d4143670 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Thu, 13 Oct 2011 21:55:55 +0200 Subject: [PATCH] allowing for vector of deterministic shocks --- doc/dynare.texi | 19 ++++++++++++++++--- matlab/set_shocks.m | 12 ++++++++++-- tests/ramst_vec.mod | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 tests/ramst_vec.mod diff --git a/doc/dynare.texi b/doc/dynare.texi index a7473fd90..5b16f4576 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -2070,9 +2070,10 @@ It is possible to specify shocks which last several periods and which can vary over time. The @code{periods} keyword accepts a list of several dates or date ranges, which must be matched by as many shock values in the @code{values} keyword. Note that a range in the -@code{periods} keyword must be matched by only one value in the -@code{values} keyword: this syntax means that the exogenous variable -will have a constant value over the range. +@code{periods} keyword can be matched by only one value in the +@code{values} keyword. If @code{values} represents a scalar, the same +value applies to the whole range. If @code{values} represents a vector, +it must have as many elements as there are periods in the range. Note that shock values are not restricted to numerical constants: arbitrary expressions are also allowed, but you have to enclose them @@ -2097,6 +2098,18 @@ values (1+p) (exp(z)); end; @end example +A second example with a vector of values: + +@example +xx = [1.2; 1.3; 1]; + +shocks; +var e; +periods 1:3; +values (xx); +end; +@end example + @customhead{In stochastic context} For stochastic simulations, the @code{shocks} block specifies the non diff --git a/matlab/set_shocks.m b/matlab/set_shocks.m index 410d3b5f4..d6fead20a 100644 --- a/matlab/set_shocks.m +++ b/matlab/set_shocks.m @@ -48,11 +48,19 @@ end switch flag case 0 - oo_.exo_simul(k,ivar) = repmat(values,length(k),1); + if size(values,1) == 1 + oo_.exo_simul(k,ivar) = repmat(values,length(k),1); + else + oo_.exo_simul(k,ivar) = values; + end case 1 oo_.exo_simul(k,ivar) = oo_.exo_simul(k,ivar).*values; case 2 - oo_.exo_det_simul(k,ivar) = repmat(values,length(k),1); + if size(values,1) == 1 + oo_.exo_det_simul(k,ivar) = repmat(values,length(k),1); + else + oo_.exo_det_simul(k,ivar) = values; + end case 3 oo_.exo_det_simul(k,ivar) = oo_.exo_det_simul(k,ivar).*values; end diff --git a/tests/ramst_vec.mod b/tests/ramst_vec.mod new file mode 100644 index 000000000..6085a1193 --- /dev/null +++ b/tests/ramst_vec.mod @@ -0,0 +1,38 @@ +var c k; +varexo x; + +parameters alph gam delt bet aa; +alph=0.5; +gam=0.5; +delt=0.02; +bet=0.05; +aa=0.5; + + +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; +x = 1; +k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1)); +c = aa*k^alph-delt*k; +end; + +steady; + +check; + +a=[1.2; 1.1]; + +shocks; +var x; +periods 1:2; +values (a); +end; + +simul(periods=200); + +rplot c; +rplot k;