%  hsdemo6.m
clc
clg
echo on
%
%        Aggregation over Time in a Permanent Income Model
%
%   This demo takes our equilibrium version of Hall's consumption
%   model and obtains distinct impulse response functions of
%   consumption.
%
%   The first impulse response function is simply the response
%   of consumption to an innovation in the endowment shock process.
%
%   The second impulse response function is the response of a
%   three period moving sum of consumption to an innovation
%   in its Wold representation.
%
%   The comparison between these two impulse response functions
%   is designed to illustrate the effects of aggregation over time.
%   Thus, the demonstration illustrates the ``Working effect.''
%
pause    % press any key to continue the demonstration
clc
%
%
%
%   First we read in the parameters of Hall's econonomy with small
%   costs of adjusting capital, which we've stored in clex11.m.
%   then we use solvea.m to compute the equilibrium.
%
pause    %  press any key to continue the demonstration
clex11
echo off
solvea
echo on

%
%
pause    %     Press a key to see sc
%

sc
%
%
pause   %  press a key to continue the demonstration
clc
%
%
%

         %  Press a key to compute the impulse response function of
         %  consumption and investment  with respect to the endowment shock.
         %  Notice that the impulse response for consumption (the solid
         %  line) has a an open-ended box shape.  This is a symptom
         %  of consumption being a random walk.
pause    %


sy=[sc;si];
z=aimpulse(ao,c,sy,1,22);
v=[0 20 0 1];
axis(v)
jj=[0:20];
plot(jj,z(2:22,:)),title('response of cons and invest to endowment innov')...
,pause

clc
%
%
%
%   Now we'll compute the impulse response function of the `unit averaged
%   data', i.e., the data that are three period moving sums of the
%   raw consumption data.
%
%   First, we use `avg.m' to create the appropriately stacked
%   state-space system that governs the augmented state
%   X(t) = [x(t)' x(t-1)' x(t-2)']'.
%
pause   %  press a key to continue
[AA,CC]=avg(ao,c,3);
%
%
      %   press a key to create the `observer matrix' that
      %   picks off a three period moving sum of consumption,
pause %   namely, G=[sc sc sc];

G=[sc sc sc];
%
%
%      Now create R and D matrices for preparation of the Kalman
%      filtering procedure used in `aggreg'.
%
pause   %  press a key to continue
R=.0001;D=0;
%
%
%
%  Now form the Wold representation (innovations representation)
%  that governs the three-period moving sum of consumption.
[Ar,Cr,aa,bb,cc,dd,V1]=aggreg(AA,CC,G,D,R,3);
%
%
clc
%
%
%
       %   press a key to get impulse response
       %   function of the moving sum of consumption
       %   Notice that the impulse response function is no long
       %   that associated with a random walk, i.e., it's not
       %   an open-ended box.  Instead, it has the characteristic
       %   shape of a process whose first difference is a first order
       %   moving average.
pause


y=dimpulse(aa,bb,cc,dd,1,22);
v=[0 20 0 1.4];
axis(v)
plot(jj,y(2:22)),title('impulse response of moving average of cons'),pause
%
%
axis
pause  %  press a key to return to the menu


