Macro2 Hw1 Matlab

  • Upload
    latarn

  • View
    222

  • Download
    0

Embed Size (px)

Citation preview

  • 8/14/2019 Macro2 Hw1 Matlab

    1/9

    ---

    Lecture Note: Business Cycles ModelVimut VanitcharearnthumUniversity of the Thai Chamber of Commerce

    March 5, 2009

    1 A Prototype ModelA representative agent maximizes

    Eo L0 (3tu (Ct, 1 - nt) . (1)t=O

    where u(Ct, 1 - nt) = a In(ct) + (1 - a) In(1 - nt) . The budget constraint isCt + kt+1 = eZtkfni-O+ (1 - 6)kt . (2)

    The technology shock is assumed to follow the AR(I) process. That is,Zt+l = pZ t + Et+l . (3)

    The first-order conditions are1a-

    Ct1(l-a)--.f 1- nt

    At1.1 Steady State

    I-aI-n1

    {3c

    (4)A (1 - B)eZt kOn -0t t , (5)

    (6)

    (7)(8)(9)

  • 8/14/2019 Macro2 Hw1 Matlab

    2/9

  • 8/14/2019 Macro2 Hw1 Matlab

    3/9

    Variables Steady State Valuesr 0.0454k 10.52y 1.19c 0.93

    Table 2: Computed Steady State Values1.3 Log-linearized

    C f N l ~ o \ '-I.- - ~ - " ~ wl(Q..,- ~ ~ t v t3 = At, IS ( (10)n A A

    --1-nt At + ekt - ent + Zt , (11)- n '\t+l + 3A(e - 1)rkt+1+ /3(1 - e)rn:+1 + /3rZt+l ,(12) (~ + ~ ~ ~ t ,+ (1 - e)1/&)+ ( ~ _ ~ 8)kkt . \ (13) f

    L.- ~ J . P J s - t " ' e o ~ ~ - t t - v. r--' e } C o ~ l I ' e o v t J ~ \ - - t i l \ " L2 Constructing A State-space System

    (11) can be rewritten as( e - _n_) nt = ,\t + ekt + Zt , (14)1 -n

    ~ k ~ ( l t " , > r or, tot~ Ao { ~ G \ l ( t , nt =

  • 8/14/2019 Macro2 Hw1 Matlab

    4/9

    --

    where r k / ' 0 n ;C]< \:I __1Ao = t,6(l- 1 I ) ~ [ 4 > o -l j)2+ { 3 r ( ~ -= 1I)4>J ~ { 3 ~ ( 1 ~ ~ ~ l 2 y[O + (1 - .8)0] + (1 - 6)k C -1+ (1 - 8)Y1 y(1 + (1 - 8)1 ]

    Al = 0 1 0[ o . 0 pThe above system can also be rewritten as

    + B Et+l , (17)

    where A = Ail l A l and B = Ail l [ ] . Using these numerical values, weare able to construct the matrices A and B below

    [ ~ : : ~ ]. [ ! O ~ ; 4 ( ~ . ; } --1l!Li ] .[ ~ ]+ [ - O 77 ] Et+ l ' (18)Zt+l 0 0 0.8 Zt 1A BTo decouple the dynamics of this system, we need to find the eigenvaluesand the eigenvectors of the matrix A. Matlab can help us find them easily.

    Just use the command "eig". For example, simply type[V,D] = eig(A)will give us the matrix of eigenvectors (V), and the diagopal matrix of. 1 D A I " n ~ h t 9 . U IM ' IVelgenva ues, . ( ~ - \ ' t b {OjVlloll\.tAHV , f-In our model, the diagonal matrix i S ~ i S tv h Z : ~ : J \i(\.tvv \'- (Iv... 0 A.\ /J-tJ.. ,} J.I'.t-' toll/", v ~ ~ ~ '--- 't _ [1.978 0 0] b(vJ Kt s.D - 0 0.399 0 .o 0 0.8Notice that the eigenvalue in the first row has a value outside a unitcircle. This is the unstable root that we can use to eliminate >. from our

    dynamical system. That is, we are able to write>' as a linear combinationof it, and z, the endogenous and exogenous state variables of our model.

    It-.q =- PZt + ~ f , - t , 4~ ' t + \ "::; 1 . l . f ~ kt- + to, 'l-') At

  • 8/14/2019 Macro2 Hw1 Matlab

    5/9

    v.J == /yw(v)The above state-space ystem can be rewritten as - W(1 11)/W(1/2-)

    kt+ I ] = [ k t] + -0.77 ]t + I DV- I At [ E t+ I , (19)[ ~ + 1or,

    co- -11tk V -I J ~ = ZR[ t ]+ [ - o 77 ] Et+I , (20)5 ~ ~ t + I 11 Zt 1d ,,,,,e", , , . , , . j ~ N \ 0et rid of ).++1 T h ~ F s t - e q u a ' b ~ W ~ i ~ t g i s system is/ ~ ( J i ) VI,lkt+l + VI,2.xt+1 + VI,azt+l)= 1.98(VI,lkt + VI,2.x t + VI,aZt) ,I -where v(l,j) is the first row of matrix V-I.

    Since this is the equation associating with the unstable root (1.98 > 1),th e linear combination in th e parenthesis has to be zero. Therefore, we areable to write vtt",'() A I rT\_ . kt-,--t-, -::. S , 4 ? Kt' -1: 0.'Z)\(-.!J

    A AI V I3 .At = ' ~ - -'Zt . -+- " l- I. { CVI 2 VI 2 tr'~ L ~ ~ ~ , i ) ' ..",.,se this relationship in ~ ~ a ~ - - t o 6 P t - a i R _k+I = 0.399kt + 0.239zt . "" -""-"",' ...

    Finally, the law of motion ofthestate variables in this model is""---------

    k t+I ] = /'["/0'399. ,,,,0, .23;/1 [ kt ] + [ ]Et+I (21)[ Zt+I ,0;8 J Zt 1v..DD3 Impulse Response Function /Suppose we are interested in the dynamic impact of a one-time increase in /the innovation to technological change, Et . /The impact of Et on kt+I an d Zt+ I is

    ltft,u of (\I\o-tllm u f [ kt+I ] = [0.399 0.239] [ ] 0.239 ]L r.- Zt+I ' 0.8 1 [ 0.8 /l C l . \ ~ (l r M/) tiOVl Or 1; /1\

    -:;:! -Ct 5

    ACt-

    IJvAV1t :::.

  • 8/14/2019 Macro2 Hw1 Matlab

    6/9

    The impact of Et on k+2 and Zt+2 isk+2 ] = [0.399 0.239] [0.399 0.239"] [ 0 ]

    "[ Zt+2 0 0.8 0 0.8 1

    = [ O O ~ 6 3 4 4 ] .The impact of Et on kt+i and Zt+i is

    kt+i "] = [0.399 0.239] i [ 0 ][ Zt+i 0 0.8 1Here is the Matlab code for computing the impulse response function,M = zeros(2,200);For i = 1:200 1;1:':,; A\i*[O;1 ; '(\ ('1-\/ 'C . / )V0~ I ~ - , ~ ( ) 9" l""-'\ J

    p r .) -::; l\> . ~ o / \ } ')t!'Co')v \)0'"v " rN .0v' l (V]

    -1V Vt-t-rL--v-_...j\ Ii\ 0. 'J e" V\ ~ n V l ~ fj (IV\

    6

  • 8/14/2019 Macro2 Hw1 Matlab

    7/9

    .I1O ..000 Mauro! Date ? .I t?1.. .

    I' 1 hMere.. Xok =- lA\, 0 -- fA1 0 0 . - ,I 'A4; \ 0 }A2. ()li j 0 }A 1..

    () ,4\

    -z..,.....- 0 xoc D1 - -X

    AAC1 71'") Kt + AC172-) . . 'ri(1,3) l . ..... , 4 (13 )2

    1\'(1 ~ - A(17-)

  • 8/14/2019 Macro2 Hw1 Matlab

    8/9

    MFile(MATLAB)

    %ThisisanMfileformyfirstRBCModel.

    %Settingparametervalues.

    beta=0.98;

    theta=0.4;

    alpha=0.33;

    delta=0.025;

    n=0.28;

    rho=0.8;

    phi1=1/(theta(n/(1n)));

    phi0=phi1*theta;

    %Steadystatevalue

    r=1/beta (1delta);

    yk=r/theta;

    kn=yk^(1/(theta1));

    k=kn*n;

    y=yk*k;

    c=ydelta*k;

    %ConstructMatrices

    a4=beta*(1theta)*r*(phi01);

    a5=2+beta*r*(1

    theta)*phi1;

    a6=beta*r*(1theta)*phi1+1;

    A0=[k00;a4a5a6;001];

    a1=y*(theta+(1theta)*phi0)+(1delta)*k;

    a2=(1/c)+(1theta)*y*phi1;

    a3=y*(1+(1theta)*phi1);

    A1=[a1a2a3;010;00rho];

  • 8/14/2019 Macro2 Hw1 Matlab

    9/9

    %CalculatingMatrix

    A=inv(A0)*A1;

    B=inv(A0)*[0;0;1];

    [V,D]=eig(A);

    W=inv(V);

    %The1steigenvaluesisoutsidetheunitcircle.Therefore,weimposethat

    %thetransformedvariableinthe1strowofmatrixV*Xequalszero

    DD=[A(1,1)(A(1,2)*(W(1,1)/W(1,2)))A(1,3)(A(1,2)*(W(1,3)/W(1,2)));0rho];

    %ComputingImpulseResponseFunction

    %onetimeincreaseintechnologyshock

    M=zeros(2,200);

    fori=1:200

    M(:,i)=DD^i*[0;1];

    end;

    Y=M';

    plot(Y)

    %ImpulseResponseFunctionforConsumption,IncomeandLabor

    c_hat=zeros(200,1);

    y_hat=zeros(200,1);

    n_hat=zeros(200,1);

    fori=1:200

    c_hat(i)=[W(1,1)/W(1,2)W(1,3)/W(1,2)]*M(:,i);

    n_hat(i)=[phi1*(theta(W(1,1)/W(1,2)))phi1*(1(W(1,3)/W(1,2)))]*M(:,i);

    y_hat(i)=(r/theta)*M(1,i)+M(2,i);

    end;