* * Sample graphs from pages 4-15 * all 20 * * Dynamic multipliers from page 4 * set r1 = .8**(t-1) set r2 = (-.8)**(t-1) set r3 = 1.1**(t-1) set r4 = (-1.1)**(t-1) * * This sets the horizontal axis label to the symbol font. The "phi" is * represented by an f character in that font. The spgraph allows the graphs to be * placed in a 2x2 "matrix" of graphs. By default, the cells are filled going down * columns, which is why the "r3" graph is done before r2. * grparm(font=symbol) hlabel 36 spgraph(hfields=2,vfields=2,footer="Figure 1.1. Dynamic Multipliers For First-Order Difference Equations") graph(number=0,style=bar,hlabel="f=0.8",min=-1.0,max=1.0) # r1 graph(number=0,style=bar,hlabel="f=1.1",min=-7.0,max=7.0) # r3 graph(number=0,style=bar,hlabel="f=-0.8",min=-1.0,max=1.0) # r2 graph(number=0,style=bar,hlabel="f=-1.1",min=-7.0,max=7.0) # r4 spgraph(done) * * Impulse response graphs from page 5. In the first case, the w is a spike when t * is 6. This is done by using the == operator. t==6 is 1 when t is 6 and 0 * otherwise. The SET instruction uses the "first=0" option to give the series a * computable value when t is 1. If you don't put this on, y will be all missing * values because y(1)=phi*y(0)+w(1), but y(0) doesn't exist, so y(1) is missing; * which forces y(2) to be missing, etc. You have to be careful when generated * recursively defined data. * compute phi=.8 set w = (t==6) set(first=0.0) y = phi*y{1}+w grparm hlabel 24 spgraph(vfields=2,footer="Figure 1.2 Paths of Input (W) and Output (Y) Variables") graph(number=0,style=bar,hlabel="W",noticks) # w graph(number=0,style=bar,hlabel="Y",noticks) # y spgraph(done) * * In this example, the w shocks are 1 from period 6 on. The >= operator is used * to create this dummy variable. * set w = (t>=6) set(first=0.0) y = phi*y{1}+w grparm hlabel 24 spgraph(vfields=2,footer="Figure 1.3 Paths of Input (W) and Output (Y) Variables for Long-Run Effect") graph(number=0,style=bar,hlabel="W",noticks,max=6.0) # w graph(number=0,style=bar,hlabel="Y",noticks) # y spgraph(done) * * Brute force calculations of the second order difference equations. This uses the * polynomial root finder, which returns complex numbers. The coefficients are put * in from the 0 power up, so for the difference equation * y(t)=phi1*y(t-1)+phi2*y(t-2)+w, the polynomial is x**2-phi1*x-phi2, which is * input as coefficients -phi2,-phi1,1.0. The %real and %imag functions return the * real and complex parts of a complex number, %cabs gets the absolute value, and * %arg the argument (the "theta"). Note that the formulas in the text are based * at j=0, where RATS series start with T=1, which is why (T-1) is used everywhere * in the formulas. * compute lambda=%polycxroots(||-.2,-.6,1.0||) compute l1=%real(lambda(1)) compute l2=%real(lambda(2)) compute c1=l1/(l1-l2) compute c2=l2/(l2-l1) set r1 = c1*l1**(t-1)+c2*l2**(t-1) * compute lambda=%polycxroots(||.8,-.5,1.0||) compute r=%cabs(lambda(1)) compute theta=%arg(lambda(1)) compute c1i = lambda(1)/(lambda(1)-lambda(2)) compute c2i = lambda(2)/(lambda(2)-lambda(1)) compute alpha=%real(c1i),beta=%imag(c1i) * set r2 = 2*alpha*r**(t-1)*cos(theta*(t-1))-2*beta*r**(t-1)*sin(theta*(t-1)) * grparm(font=symbol) hlabel 24 spgraph(vfields=2,footer="Figure 1.4 Dynamic Multiplier for Second Order Difference Equations") graph(number=0,style=bar,hlabel="f1=0.6,f2=0.2") # r1 graph(number=0,style=bar,hlabel="f1=0.5,f2=-0.8") # r2 spgraph(done) * * Same thing, but using RATS instructions. The IMPULSE instruction is designed * precisely to compute these impulse response functions. All it needs is an * equation which describes the difference equation. This is done with the * EQUATION instruction. The syntax of EQUATION as used here is * * EQUATION(COEFFS=vector of coefficients,VARIANCE=residual variance) equation_name dependent_variable * # list of explanatory variables * * The explanatory variables here are the first and second lags of the dependent * variable. We give a variance of 1 because the IMPULSE instruction, by default, * gives the equation a one standard deviation shock, which we want to be 1. * equation(coeffs=||.6,.2||,variance=1.0) diffeq2 y # y{1 2} impulse(noprint,steps=20) # diffeq2 r1 equation(coeffs=||.5,-.8||,variance=1.0) diffeq2 y # y{1 2} impulse(noprint,steps=20) # diffeq2 r2 * * The graph is the same as above * grparm(font=symbol) hlabel 24 spgraph(vfields=2,footer="Figure 1.4 Dynamic Multiplier for Second Order Difference Equations") graph(number=0,style=bar,hlabel="f1=0.6,f2=0.2") # r1 graph(number=0,style=bar,hlabel="f1=0.5,f2=-0.8") # r2 spgraph(done)