Testing for Invertibility

I want to check invertibility for a model that has the same number of observables as shocks. If x represents the states of the system once the saddle path has been evaluated, eps represents the shocks and y represents the observables, then the reduced form can be summarised as

x(t)=A*x(t-1)+B*eps(t), y(t)=E*x(t)

(although there are other ways of representing y(t)).

I know how to obtain A and B:

A = [ ]; 
B = [ ];
state = M_.state_var';
control = [1:1:size(oo_.dr.ghu,1)]'; 
for j = 1:size(state,1)
    control( control == state(j) ) = [];
end

A = [oo_.dr.ghx( oo_.dr.inv_order_var( state ), : ) ]; 
B = [oo_.dr.ghu( oo_.dr.inv_order_var( state ), : ) ];

but how do I obtain E?

I think this could work

vObsNames = options_.varobs;
vEndoNames = M_.endo_names;
nObs = length(vObsNames);
nStates = M_.endo_nbr;

E = zeros(nObs,nStates);
for i = 1:nObs 
    E(i,:) = ismember(vEndoNames,vObsNames(i))';
end

See

and in particular DSGE_mod/FV_et_al_2007/ABCD_test.m at master · JohannesPfeifer/DSGE_mod · GitHub

Many thanks. I’ll try this and compare with the other suggestion.

Many thanks.

I note that you in your software you also convert to a minimal realization. No need to do that though:
Using my (A,B,E) notation, if (A,B) is not controllable, then there exists an eigenvalue-eigenvector pair (e,x) such that x'A=ex' and x'B=0. It is then trivial to show that x'A(I-B(EB)^(-1)B)=ex', so an uncontrollable mode of A is also an uncontrollable mode of the matrix A(I-B(EB)^(-1)B) that one is testing, so it cannot be a source of non-invertibility if the matrix A has only stable eigenvalues. An analogous result holds for non-observable modes with the e-e pair (f,y) where Ay=fy and Ey=0.

Yes, but the example in question features a unit root, which is allowed in Dynare. In that case, you need to cancel that pole.