Dynare Wouter J. Den Haan University of Amsterdam July 26, 2010 Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Introduction • What is the objective of perturbation? • Peculiarities of Dynare • Some examples Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Objective of 1st-order perturbation • Obtain linear approximations to the policy functions that satisfy the first-order conditions • state variables: xt = [x\/t Xijt %3,t • • • xn,t]' • result: Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Underlying theory • Model: Et f (g(x))] = 0, • f (x) is completely known • g(x) is the unknown policy function. • Perturbation: Solve sequentially for the coefficients of the Taylor expansion of g(x). • More info: • notes and slides on perturbation • slides on Blanchard-Kahn conditions Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Neoclassical growth model • xt = [kt-i, zt] • yt = [ct, kt, zt ] • linearized solution: ct = C + flc,k(kt-i - k)+ flc,z(zt - z) kt = k + flk,k(kt-i - k) + flk,z(zt - z) zt = pzt_i + £t Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Linear in what variables? • Dynare does not understand what a is. • could be level of consumption • could be log of consumption • could be rainfall in Scotland • Dynare simply generates a linear solution in what you specify as the variables • More on this below Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Peculiarities of Dynare • Variables known at beginning of period t must be dated t — 1. • Thus, • kt: the capital stock chosen in period t • kt—1: the capital stock available at beginning of period t Introduction Do it yourself Tricks IRFs & Simulations Pruning Peculiarities of Dynare The solution ct = c + aCfk(kt-i - k) + ac,z(zt - z) kt = k + ak,k(kt-i - k) + akiz (zt - z) Zt = pZt-i + £t can of course be written (less conveniently) as ct = C + (kt-i - k)+ ac,z_i (zt-i - z) + aCiz£t kt = k + akik(kt-i - k)+ akiz_x (zt-i - z) + akiz£t zt = pzt-i + £t with aCiz_x = pac,z and akiz_i = pakiz Practical Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Peculiarities of Dynare • Dynare gives the solution in the less convenient form: ct = c + aC/k(kt-i - k) + ac,z_t (zt-\ - z) + aCiZ£t kt = k + aKk(kt-i ~ k) + akfZ_r (zt-i ~ z) + ak,z£t Zt = pZt-1 + £t • Since the Dynare solution satisfies ac,z_x = pac,z and a^fz_x = pak,z one could always rewrite the Dynare solution in the more convenient form Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Dynare program blocks • Labeling block: indicate which symbols indicate what • variables in "var" • exogenous shocks in "varexo" • parameters in "parameters" • Parameter values block: Assign values to parameters Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Dynare program blocks • Model block: Between "model" and "end" write down the n equations for n variables • note that dynare has no conditional expectations but if an equation has a (+1) variable, then Dynare knows there is a conditional expectation Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Dynare program blocks • Initialization block: Dynare has to solve for the steady state. This can be the most difficult part (since it is a true non-linear problem). So good initial conditions are important • Random shock block: Indicate the standard deviation for the exogenous innovation Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Dynare program blocks • Solution & Properties block: • Solve the model with the command • 1st-order: stoch_simul(order=1,nocorr,nomomentsJRF=0) • 2nd-order: stoch_simul(order=2,nocorr,nomomentsJRF=0) • Dynare can calculate IRFs and business cycle statistics. E.g., • stoch_simul(order=1,IRF=30), • but I would suggest to program this yourself (see below) Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Running Dynare • In Matlab change the directory to the one in which you have your *.mod files • In the Matlab command window type dynare programname • This will create and run several Matlab files Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Model with productivity in levels (FOCs A) Specif cation of the problem c}-v max{ct,ktg E £r=i s.t. ct + kt = ztk*_x + (1 - S)kt-i zt = (1 - p)+ pzt-i + £t ko given Et[et+i] = 0 & Et[£2+i] = a2 Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Distribution of innovation • 1st-order approximations: • the distribution of et does not matter, except that Ef [et+i] has to be zero. • 2nd-order approximations: • u matters (it affects the mean) • higher-order moments do not • Also see notes and slides on perturbation theory Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Everything in levels: FOCs A Model equations: ct + kt zt Dynare equations: c~(-nu) =beta*c(+1)~(-nu)*(alpha*z(+1)*k~(alpha-1)+1-delta); c+k=z*k(-1)~alpha+(1-delta)k(-1); z=(1-rho)+rho*z(-1)+e; ztkU + (1 - 5)kt-i (1 - p)+ pzt-1 + ^ +1 6) Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Policy functions reported by Dynare • 5 = 0.025,v = 2, a = 0.36, ß = 0.99, and p = 0.95 POLICY AND TRANSITION FUNCTIONS constant k(-1) e k 37.989254 0.976540 2.597386 2.734091 z 1.000000 -0.000000 0.950000 1.000000 c 2.754327 0.033561 0.921470 0.969968 Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical !!!! You have to read output as constant k(-l)-kss z(-1)-zss e k 37.989254 0.976540 2.597386 2.734091 z 1.000000 -0.000000 0.950000 1.000000 c 2.754327 0.033561 0.921470 0.969968 • That is, explanatory variables are relative to steady state. • (Note that steady state of e is zero by definition) • If explanatory variables take on steady state values, then choices are equal to the constant term, which of course is simply equal to the corresponding steady state value Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Changing amount of uncertainty Suppose 0 Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical IRFs for linear systems • Value of kT-\ and values of original shock {gf}J=t irrelevant for IRFs • Thus, make your life easy by setting • t = 1 • gT+j = 0 for j > OTake as given ko, Zo, and time series for Et, {gf }J=1 • If k is in logs then subtract k and you have the IRF • If k is in levels calculate (kT+j — k)/k or ln(kT+j/k) Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Impulse Response functions 1st-order case: Dynare gives you kt = k + akik(kt-\ - k) + akiZ_l (zt_i - z) + aki££t • Start at k0 = k and z0 = z (= 0) • Let e\ = ae and et = 0 for t > 1 • Calculate time path for zt • Calculate time path for kt • Calculate time path for other variables • Calculate % change (subtract steady-state value if variables are in logs) Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Impulse Response functions 2nd-order case: • One could repeat procedure described in last slide • But with a non-linear law of motion results do depend on initial value of k, realizations of shocks in the original series, and whether eT = eT + u or z% = eT — u • For example, IRF can be different when initial capital stock is low than when it is high Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical How to calculate a simulated data set Dynare gives you kt = k + ak/k(kt-i - k) + ak/Z_l (zt_i - Z) + akAzt • Start at k0 = k and z0 = z (= 0) • Use a random number generator to get a series for £t for t = 1 to t = T • Calculate time path for Zt • Calculate time path for kt • Calculate time path for other variables • Discard an initial set of values • Note that procedure is the same for first and second-order solutions Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Simulate higher-order & pruning • first-order solutions are by construction stationary • simulation cannot be problematic • simulation of higher-order can be problematic • simulation of 2nd-order will be problematic for large shocks • trick proposed: Pruning • pruning: • is a trick to ensure stability • it uses a distorted numerical approximation Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Pruning k(n)(k _1,z): the nth-order perturbation solution for k as a function of k_i and z. • k(n): the value of kt generated with k(n)(-). Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Pruning For n > 1, the regular perturbation solution k(n can be written • For n as kin) - kss a(n) + 4n) (k^ - kss) + a? (zt - zss) + ~k(n)(k(% zt) Introduction Do it yourself Tricks IRFs & Simulations Pruning Practic; Pruning • With pruning one would simulate two series - kss = - kss) + az1}(zt - Zss) +k(n)(k(l)1,zt) k(n) - kss (1) • k\ is stationary as long as BK conditions are satisfied k(n) (k(1_)1,Zt) is then also stationary (n) < 1 then ensures that k\ is stationary Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Pruning • The pruned simulated series, is NOT a function of the corresponding state variables k) and zt Introduction Do it yourself Tricks IRFs & Simulations Pruning Practical Practical • Dynare expects files to be in a regular path like e:\... and cannot deal with subdirectories like //few.eur.nl/.../... • The solution is to put your *.mod files on a memory stick