% Program mdrendowment.m % Chapter 1. The basic model % One good, endownment model with perfect capital mobility % This program is part of the book "Open Economy Macroeconomics in % Developing Countries" (forthcoming MIT Press) by Carlos A. Vegh. Use of % this program or modifications thereof should be acknowledged by citing % this manuscript. This program is a modification of the original % King, Plosser, and Rebelo's (1988) programs. I am grateful to Guillermo % Vuletin for his help in writing this program. % Revised: June 2007 % This program requires as the following outputs of program dynendowment.m % nc,ns,ne,nf % Mcc,Mcs,Mce % FVc,FVke,FVl % MU,PS21,PS22 % Rke,Qke, % KTL,KEC % SP1,SP2 % Housekeeping (matrices needed only for pfe.m) clear W; clear R; clear Q; % COMPUTATION OF DECISION RULES % This program computes the Markovian Decision Rules (mdr) for the % specified linear dynamic model. The structure of forcing variables % can be altered without rerunning program #1 (dyn.m). % Let the exogenous variables be generated by a (ne x ne) vector % AR(1) process. Let the transition matrix be RHO. % Transition Matrix of Forcing Variables % Z G PI rr=input('Serial Correlation of shocks '); RHO= eye(ne,ne)*rr; % The shadow price solution requires the evaluation of a (matrix) % discounted forward sum. The strategy employed in the following % set of computations is to exploit the standard forecasting formulas % for scalar discounted sums (generalizations along Hansen-Sargent % lines for ARMA processes (if desirable) should be relatively direct.) % The composite expression that summarizes the exogenous influences % in (A48) is FL = SP1*RHO + SP2; % This is an ns x ne matrix. Partion this matrix into ns row vectors. % Then, there is a individual difference equation for each of the % transformed shadow prices equation, which can be solved in % the forward direction, with a simple application of the forecasting % formula for the relevant linear combination of the discounted sum % of exogenous variables. This is accomplished in the following do-loop. IRHO = eye(RHO); for i=1:ncs; q = FL(i,1:ne); mu2i = 1/MU2(i,i); dsum =inv((IRHO-mu2i*RHO)); LE(i,1:ne) = q*dsum; end LE; clear mu2i; clear q; clear dsum; clear i; % The matrix LE links the transformed shadow price to the exogenous % (forcing) state variables. % THE CAPITAL DECISION RULE % To derive the decision rule for capital, we need to combine the % influences of the transformed shadow price with the "direct" % influence of exogenous variables, as in (A56). Call this KEC, % where the memnonic is that this is the combined (deicison rule) % impact of the exogenous variables on capital KEC = Rke*RHO + Qke + KTL*LE; % Thus, the decision rule for capital is given by the coefficients % KLK and KEC. The decision rule for the untransformed shadow price % is given by the coefficients ULE and ULK, where ULE = PS22\LE; ULK = -PS22\PS21; % according to the formula (A55b). % SYSTEM DYNAMICS % The system dynamics are then generated by the system comprised % of states (ns elements) and exogenous variables (ne % elements). In matrix form, these are governed by the matrix M % built up as follows: % State Transition Equation (Mke) Mke = [KLK KEC zeros(ne,ns) RHO ]; % Note that this matrix incorporates the restriction that some dynamics are % exogenous, by means of zero restrictions in M. % INCORPORATION OF SHADOW PRICE, CONTROLS AND OTHER FLOWS % First we incorporate in the flow matrices defined in dyn1.m the % investment, trade balance and current account variables. To that end we % first update the number of flow variables % The shadow price is linked to the state by the ns x (ns+ne) matrix Lke = [ULK ULE]; %March 2007 comment: in this case, Lke is a 1x2 matrix, where the 1 is for %the only co-state (lambda) and the 2 is for the state (a) + the exogenous variable (y). % The solutions for the controls can be obtained by a simple application % of the optimal control equations to the optimal state equations. The % (nc x ns+ne) matrices linking the evolution of the controls to the state and % exogenous forcing variables (uncontrolled states) are calculated as follows. % The matrix linking optimal controls to states and co-states is Z=Mcc\Mcs; % This can be paritioned to separate responses to states and co-states MOck = Z(1:nc,1:ns); MOcl = Z(1:nc,ns+1:ns+ncs); % The matrix linking optimal controls to forcing variables is MOce = Mcc\Mce; clear Z; clear Mcc; clear Mcs; clear Mce; % These expressions can be combined with the structure for the optimal shadow % price vector, given above, to obtain a link between optimal controls and the % optimal state vector. MOcke = [MOck+MOcl*ULK MOce+MOcl*ULE]; %March 2007: in this case, this is a 1x2 (1 for the only control and 2 for %state + exogenous. % The additional matrices derived in program #1 link (nf) flow variables % to controls, states, costates and exogneous forcing variables. % The flow variables are consequently linked to the k,e vector by: Fke =[FVc*MOcke+FVke+FVl*Lke]; clear MOce; clear MOcl; % RATES OF RETURN % It is sometimes valuable to study commodity rates of return on the capital % goods of the economy. The direct method of doing this is to analyze the % rate of change of shadow prices. From above, we know that % the shadow price is linked to the state by the ns x (ns+ne) matrix % Lke = [ULK ULE] and that the capital stock and exogenous forcing % variables evolve according to % % Mke = [KLK KEC % zeros(ne,ns) RHO ]; % % Thus, the conditional expectation of next period's shadow price is % given by multiplying [ULK*KLK (ULK*KEC+ULE*RHO)] and the state vector. % Thus, using the fact that the rate of return is equal to minus the rate % of change of price, it follows that the following matrix determines % movements in expected rates of return. RRke = [ULK-ULK*KLK ULE-(ULK*KEC+ULE*RHO)]; % Thus, the stacked vector of shadow prices, controls, other flows and % returns is linked to the state vector by the (ns+nc+nf+ns x ns+ne) matrix % ' H Matrix Linking Costate,Control,' % ' Other Flows and Returns to State Vector' H = [Lke MOcke Fke RRke]; % Eliminate spurious complex numbers in the output if max(imag(H))<10e-10 H=real(H); end if max(imag(Mke))<10e-10 Mke=real(Mke); end % disp('Variables in H are ordered as follows') % disp('lambda, c, TB') clear Lke; clear MOcke; clear Fke; clear RRke; clear Rke; clear Qke; clear SP1; clear SP2; clear PS21; clear PS22; clear MU2 clear FL; clear KTL; clear ULK; clear ULE; clear FVc; clear FVke; clear FVl; clear MOck; clear LE; clear FL; clear RHO; clear IRHO; clear KLK; clear KEC;