* * DSGEHISTORY.RPF * Computation of the historical decomposition for a DSGE model. * * Based upon the CAGAN.RPF example from RATS User's Guide, Section * 10.8.5. * open data cagan_data.prn data(format=prn,org=cols) 1 34 mu x * declare series a1 a2 eps eta declare real alpha lambda sig_eta sig_eps * frml(identity) f1 = x -(x{1}+a1-lambda*a1{1}) frml(identity) f2 = mu-\$ ((1-lambda)*x{1}+lambda*mu{1}+a2-lambda*a2{1}) frml(identity) f3 = a1-1.0/(lambda+(1-lambda)*alpha)*(eps-eta) frml(identity) f4 = a2-(1.0/(lambda+(1-lambda)*alpha)*\$ ((1+alpha*(1-lambda))*eps-(1-lambda)*eta)) frml d1 = eps frml d2 = eta * group cagan f1 f2 f3 f4 d1 d2 * * lambda+(1-lambda)*alpha needs to stay clear of its zero point. It * appears that it needs to be negative, so alpha must be less than * -lambda/(1-lambda) on the guess values. * compute alpha=-3.00,lambda=.7,sig_eta=.001,sig_eps=.001 ***** function EvalModel dsge(model=cagan,a=adlm,f=fdlm) x mu a1 a2 eps eta end EvalModel ***** compute EvalModel() compute cdlm=%identity(2)~~%zeros(%rows(adlm)-2,2) * * Because we really have no idea what the scale is on the variances, we * first estimate the model with the alpha and lambda fixed. This uses * only a small number of simplex iterations to get the sigmas into the * right zone. * nonlin sig_eta sig_eps dlm(start=%(EvalModel(),sw=%diag(||sig_eps^2,sig_eta^2||)),\$ a=adlm,f=fdlm,y=||x,mu||,c=cdlm,sw=sw,presample=ergodic,\$ method=simplex,iters=5,noprint) * nonlin alpha lambda sig_eta sig_eps dlm(start=%(EvalModel(),sw=%diag(||sig_eps^2,sig_eta^2||)),\$ a=adlm,f=fdlm,y=||x,mu||,c=cdlm,sw=sw,presample=ergodic,\$ pmethod=simplex,piters=5,method=bfgs) * * Historical decomposition * Compute the Kalman filtered w shocks (into WHAT). * dlm(start=%(EvalModel(),sw=%diag(||sig_eps^2,sig_eta^2||)),\$ a=adlm,f=fdlm,y=||x,mu||,c=cdlm,sw=sw,presample=ergodic,\$ type=filter,method=solve,what=what) compute gstart=%regstart(),gend=%regend() * * Compute the incremental effect of the shocks, given the dynamics of the model. * This starts with a zero presample value for the states and extrapolates that * using the state equation, adding in only one set of historical shocks in each * pass. * dec vect[series[vect]] yhist(2) gset yhist(1) = %zeros(2,1) gset yhist(2) = %zeros(2,1) do i=1,2 compute x0=%zeros(%rows(adlm),1) do time=gstart,gend compute x0=adlm*x0+fdlm*(what(time).*%unitv(%size(what(time)),i)) * * Extract just the observable states * compute yhist(i)(time)=tr(cdlm)*x0 end do time end do i * spgraph(footer="Cumulative Effects of Shocks",vfields=2,\$ key=below,style=lines,klabels=||"Money Growth Shock","Money Demand Shock"||) set x_to_eps = yhist(1)(t)(1) set x_to_eta = yhist(2)(t)(1) graph(header="Inflation") 2 # x_to_eps # x_to_eta set mu_to_eps = yhist(1)(t)(2) set mu_to_eta = yhist(2)(t)(2) graph(header="Money Growth") 2 # mu_to_eps # mu_to_eta spgraph(done)