/* findrule: given captial and consumption equations, solves model for captial consumption elasticities, state vector transition and endogenous variable rules usage: {A,C,nc} = findrule(phim,cphi,ak,aa,ac,g0,ga,gk); inputs: phim,cphi: [az](t+1) = phim [az](t) + cphi e; E(ee')=I ak,aa,ac,g0,ga,gk: k' = ak k + aa a + ac c t c t+1 = g0 ct + ga t at+1 + gk t kt+1 outputs: A,C: [k a z]' = A [ k a z ]' + C e E(ee') = I nx: x = nx [k a z]' --------------------------------------------------------------------*/ clearg l1,l2,l3; proc(3) = findrule(phim,cphi,ak,aa,ac,g0,ga,gk); local va,b,disc,nck,rf,of,oz,ncaz,nc,a,abig,cbig,ctoy,nn,ny,ni,iy,ic, q0,q1,q2,nckc; /* check input */ va=eig(phim); if maxc(abs(va)) > 1; "phi matrix has eigenvalues > 1 "; endif; /* find consumption decision rule */ /* capital */ b = (ak-g0-gk*ac); disc = b^2 + 4*ac*gk*ak; nck = (-b - (disc)^(1/2))/(2*ac); if nck < 0; "trying other root of nck"; nck = (-b + (disc)^(1/2))/(2*ac); if nck < 0 ; "Error nck <0 "; endif; endif; /* diagnostics " b" b; " b^2" b^2; " c " -ak*gk; " a " ac; " 4ac" 4*ac*gk*ak; "disc" ( b^2 + 4*ac*gk*ak); " nck" (((-b - (disc)^(1/2))/(2*ac))|((-b + (disc)^(1/2))/(2*ac))); */ /* check campbell solution */ /*( this works. needs global l1,l2, ...) */ /* Q2 = (1+l3*v)*(1-l1-l2*(1+v)); Q1 = (1+l3*v)*(l1+l2*(1-alph)*v)-l3*((1-alph)*v-1)*(1-l1-l2*(1+v))-1; Q0 = -l3*((1-alph)*v-1)*(l1+l2*(1-alph)*v); nckc = 1/(2*q2)*(-q1-(q1^2-4*q0*q2)^(1/2)); "Q2" Q2; "Q1" Q1; "Q0" Q0; */ /* other shocks */ rf = rows(phim); /* no. of shocks */ of = zeros(rf,1); if rf >= 2; oz = zeros(rf-1,1); ncaz = (1~oz')*(aa*(gk-nck)*eye(rf)+ga*phim)* inv(eye(rf)*(ac*(nck-gk)-g0)+phim); ncaz = ncaz'; endif; if rf == 1; ncaz = (aa*(gk-nck)+ga*phim)* inv((ac*(nck-gk)-g0)+phim); ncaz = ncaz'; endif; nc = nck|ncaz; /* transition for state variables */ /* [k a z]' = abig [k a z]' + C e E(ee') = I */ if rf >= 2; A = (ak ~ aa ~ zeros(1,rf-1))| (of~phim); endif; if rf == 1; A = (ak ~ aa)| (of~phim); endif; Abig = A + (ac|of)*nc'; Cbig = zeros(1,cols(cphi))|Cphi; retp(Abig,Cbig,nc); endp;