Resid

Topics: Models
May 15, 2014 at 9:27 PM
Hi, is there a function to compute the equation residuals for the given initial values?

Thanks.
Coordinator
May 15, 2014 at 9:33 PM
If you mean the discrepancy between the left-hand side and the right-hand side, you can use the function lhsmrhs(...) (which stands for LHS Minus RHS). Keep in mind that you need to supply all variables, and that all leads (=expectations) are filled in with the actual future values.

If you mean computing structural shocks on the history, use the Kalman filter, i.e. the function filter(...).

Jaromir
Marked as answer by jaromirbenes on 5/15/2014 at 2:33 PM
May 20, 2014 at 2:17 PM
Hi Jaromir,

I am trying to check if the equations in steady state are satisfied at the initial values. Should I use the lhsmrhs function?

Thank you

Camila Londoño
May 20, 2014 at 2:48 PM
Edited May 21, 2014 at 11:18 PM
Here is my version of chksstate which show the equations AND the residuals sorted in descending order exceeding the given tolerance.
function [ Discr, Eqtn ] = chksstate2( m, tol )
% chksstate2  Check if equations hold for currently assigned steady-state values.
%
% Syntax
% =======
%
%     [Discr,List] = chksstate(M,tol)
%
% Input arguments
% ================
%
% * `M` [ model ] - Model object.
% * `tol` [numeric] - Tolerance
%
% Output arguments
% =================
%
% * `Discr` [ numeric ] - Discrancy between LHS and RHS evaluated for
% each equation at current period of time.
%
% * `Eqtn` [ cellstr ] - List of equations in which the discrepancy between
% LHS and RHS is greater than `'tolerance='`.
%
%

[d,x,e,islog,Tmin,Tmax,Eqtn]=get(m,'sstate','xList','eList','log','maxLag','maxLead','xEqtn');
L=[nan(size(x)) zeros(size(e))]; G=L;
T=Tmin:Tmax;
for i=1:size(x,2)
    L(i)=real(d.(x{i}));
    G(i)=imag(d.(x{i}));
    if islog.(x{i})
        d.(x{i})=tseries(T,L(i)*G(i).^T);
    else
        d.(x{i})=tseries(T,L(i)+G(i)*T);
    end
end
for i=1:size(e,2)
    d.(e{i})=tseries(T,d.(e{i}));
end
YXE=data4lhsmrhs(m,d,T);
Discr=lhsmrhs(m,YXE,L);
[Discr,id]=sort(abs(Discr(:,1-Tmin)),'descend');
Eqtn=Eqtn(id);
for i=1:find(Discr<tol,1)-1
    warning('%d: %s\n',Discr(i),Eqtn{i});
end
Discr=Discr(1:i);
Eqtn=Eqtn(1:i);
Marked as answer by jaromirbenes on 5/20/2014 at 7:59 AM
Coordinator
May 20, 2014 at 2:59 PM
Hi Camila,

Use the function chksstate(m). This function is meant to verify whether the equations hold for the currently assigned steady-state values. If there are discrepancies greater than a tolerance level, an error is thrown by default showing the list of equations that cause the trouble. You can modify the behavior of the function using some of its options; see idoc model/chksstate.

The function lhsmrhs(...) is meant for something different -- to check the equations using a given database of time series.

Best,
Jaromir
Marked as answer by jaromirbenes on 5/20/2014 at 7:59 AM
Coordinator
May 20, 2014 at 3:00 PM
Camila,

One more question -- what do you exactly mean by "initial values"?

J.
May 20, 2014 at 9:32 PM
Thanks for your response,

I have a non-linear steady state, so I’m providing initial points (a guess of the steady state) to guide the optimizer. I want to check if my initial values really satisfied the equations. What can I do?
I guess I could use the initial values as the steady state and run the chksstate, so that the program would identify the equation with a discrepancy.
Is this a good idea?


Camila
Coordinator
May 21, 2014 at 2:11 PM
Edited May 21, 2014 at 2:12 PM
Hi Camila,

The initial points don't have to satisfy the equations (otherwise, that would mean you've already found out the steady state, and don't have to run the steady state solver).

What you do instead, is the following:
  1. You may or may not specify initial values for some of the variables. This is a totally optional step, you don't have to do it. The only substantial difference it makes is in the case of variables whose steady state ends up being some very large or very small number (think, e.g., of the stock of capital in the traditional variety of neoclassical models -- the level of capital is typically much larger than output or consumption or labor, etc). If you do want to assign some initial values, you do it right in the model object, e.g.
>> m.Y = 1.5;
>> m.K = 20;
etc.
  1. You run the function sstate(...) which computes the steady state. It starts from the initial values you supply and some default initial values for variables for which you don't supply any initial values, and iterates using the Optimization Tbx until convergence. Note that you need to use the option 'growth=' true if the model has deterministic growth rates in the long run. Also, you may want to use the option 'blocks=' true to decompose the model into recursive blocks, which helps things a lot, too.
  2. When/if the funciton sstate(...) successfully computes the steady state, the steady state for each variable is assigned in the model object. There are many ways how to view/retrieve the computed steady-state values, e.g.
>> m.Y
>> get(m,'sstate')
>> get(m,'sstateLevel')
>> get(m,'sstateGrowth')
  1. Finally, it's a good idea with nonlinear models to verify that the steady state is accurate (enough). To that end, run the function chksstate(m).
It might be useful for you to look into some of the tutorials that actually handle these kinds of things.

Best,
Jaromir