Re: Q: Solving econometric models
- To: mathgroup at smc.vnet.net
- Subject: [mg30984] Re: [mg30859] Q: Solving econometric models
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Sat, 29 Sep 2001 04:19:03 -0400 (EDT)
- References: <200109200752.DAA16383@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"Mark S. Coleman" wrote: > > Greetings: > > I apologize in advance for the rather vague nature of this question, > but I am hoping that MathGroup members might be able to point me in > the right direction. > > I am working with a number of small econometric models that I have > estimated (using Regress) in Mathematica v4.0. The models support a number of > out-of-sample economic forecasting applications. As part of the > research I am conducting, I need to 'solve' these equations -- that > is, generate projections of future economic activity. This type of > functionality is generally a standard part of "conventional" > statistical/econometric packages, and I am seeking to replicate this > functionality in Mathematica. > > To illustrate the problem, consider the following very simple > two-equation model (note that I am not using Mathematica notation here): > > y(t) = a + b*y(t-1) + c*x(t) > z(t) = d + e*z(t-1) + f*y(t-1) > > where t denotes time, y,z, and x are variables, and {a...f} are= > real > numbers (say estimated using Regress). Assume that > t=1,...,n,n+1,n+2,...,T. > > Assume that the models were estimated using the sample of data from > 1,...,n. The objective is to solve or forecast this model over the > future periods n+1, n+2,...,T. Also assume that x(t) is known over > the future periods. > > In my attempts to solve this problem in Mathematica, I've created a list of > rules (taken from the BestFit option in Regress) and then 'looped' > over the list of future periods, one period at a time, and used the > ReplaceAll function. > > This raises a couple of questions. First, to use prior solved values, > I've had to create a new equation to define each of the lagged > values, y(t-1) and z(t-1). Is there a better way to handle this? > > Second, can the model be written in Mathematica notation to solve over the > entire set of future time periods without the use of an explicit > loop? > > Any help would be greatly appreciated. > > -Mark You have a system of linear recurrences and this can be solved with the RSolve standard add-on package as below. In[1]:= <<DiscreteMath`RSolve` In[2]:= eqns = {y[t] == a + b*y[t-1] + c*x[t], z[t] == d + e*z[t-1] + f*y[t-1]}; In[3]:= InputForm[RSolve[eqns, {y[t],z[t]}, t]] Out[3]//InputForm= {{y[t] -> Sum[-((C[1]*If[K[1] == 0, 1, 0])/(-1 + b)) + (b^(2 + t - K[1])*C[1]*If[K[1] == 0, 1, 0])/(-1 + b) - If[K[1] == 1, a - C[1], 0]/(-1 + b) + (b^(2 + t - K[1])*If[K[1] == 1, a - C[1], 0])/(-1 + b) + (c*x[-2 + K[1]])/(-1 + b) - (b^(2 + t - K[1])*c*x[-2 + K[1]])/(-1 + b) - (c*x[-1 + K[1]])/(-1 + b) + (b^(2 + t - K[1])*c*x[-1 + K[1]])/(-1 + b), {K[1], 0, 1 + t}], z[t] -> Sum[-((C[2]*If[K[1] == 0, 1, 0])/((-1 + b)*(1 - e))) - (b^(3 + t - K[1])*C[2]*If[K[1] == 0, 1, 0])/((-1 + b)*(-b + e)) + (e^(3 + t - K[1])*C[2]*If[K[1] == 0, 1, 0])/((-1 + e)*(-b + e)) + If[K[1] == 1, -d - f*C[1] + (1 + b)*C[2], 0]/((-1 + b)*(1 - e)) + (b^(3 + t - K[1])*If[K[1] == 1, -d - f*C[1] + (1 + b)*C[2], 0])/ ((-1 + b)*(-b + e)) - (e^(3 + t - K[1])*If[K[1] == 1, -d - f*C[1] + (1 + b)*C[2], 0])/((-1 + e)*(-b + e)) + If[K[1] == 2, f*(-a + C[1]) + b*(d - C[2]), 0]/((-1 + b)*(1 - e)) + (b^(3 + t - K[1])*If[K[1] == 2, f*(-a + C[1]) + b*(d - C[2]), 0])/ ((-1 + b)*(-b + e)) - (e^(3 + t - K[1])*If[K[1] == 2, f*(-a + C[1]) + b*(d - C[2]), 0])/((-1 + e)*(-b + e)) + (c*f*x[-3 + K[1]])/((-1 + b)*(1 - e)) + (b^(3 + t - K[1])*c*f*x[-3 + K[1]])/((-1 + b)*(-b + e)) - (c*e^(3 + t - K[1])*f*x[-3 + K[1]])/((-1 + e)*(-b + e)) - (c*f*x[-2 + K[1]])/((-1 + b)*(1 - e)) - (b^(3 + t - K[1])*c*f*x[-2 + K[1]])/((-1 + b)*(-b + e)) + (c*e^(3 + t - K[1])*f*x[-2 + K[1]])/((-1 + e)*(-b + e)), {K[1], 0, 1 + t}]}} In[4]:= x[t_] := Sin[t] + t; In[5]:= a = 3; b = 7; c = 4; d = 2; e = 5; f = 8; Using specific values for x[t] and the parameters we get something nicer. In[6]:= InputForm[RSolve[eqns, {y[t],z[t]}, t]] Out[6]//InputForm= {{y[t] -> If[t >= -1, (252*I - (36*I)*E^I + (36*I)*E^(I + (2*I)*t) - (252*I)*E^((2*I)*(1 + t)) + 7*E^(I*t)*(-23 + (77 - 36*I)*7^t - 12*t + 18*7^(1 + t)*C[1]) + 7*E^(I*(2 + t))*(-23 + (77 + 36*I)*7^t - 12*t + 18*7^(1 + t)*C[1]) - 50*E^(I*(1 + t))*(-23 + 11*7^(1 + t) - 12*t + 18*7^(1 + t)*C[1]))/(18*(7 - 50*E^I + 7*E^(2*I))*E^(I*t)), 0], z[t] -> If[t >= -1, ((10080*I)*E^I - (3456*I)*E^(2*I) + (288*I)*E^(3*I) - (288*I)*E^(I + (2*I)*t) - (10080*I)*E^(3*I + (2*I)*t) + (3456*I)*E^((2*I)*(1 + t)) + 144*E^(I*(3 + t))* (-129 + (189 + 50*I)*5^(1 + t) - (132 + 26*I)*7^(1 + t) - 72*t + 216*(5^(1 + t) - 7^(1 + t))*C[1] - 54*5^(1 + t)*C[2]) + 144*E^(I*(1 + t))*(-129 + (189 - 50*I)*5^(1 + t) - (132 - 26*I)*7^(1 + t) - 72*t + 216*(5^(1 + t) - 7^(1 + t))*C[1] - 54*5^(1 + t)*C[2]) - 35*E^(I*(4 + t))*(-43 + (315 + 144*I)*5^t - (308 + 144*I)*7^t - 24*t + 72*(5^(1 + t) - 7^(1 + t))*C[1] - 18*5^(1 + t)*C[2]) - 35*E^(I*t)*(-43 + (315 - 144*I)*5^t - (308 - 144*I)*7^t - 24*t + 72*(5^(1 + t) - 7^(1 + t))*C[1] - 18*5^(1 + t)*C[2]) - 1370*E^(I*(2 + t))*(-43 + 63*5^(1 + t) - 44*7^(1 + t) - 24*t + 72*(5^(1 + t) - 7^(1 + t))*C[1] - 18*5^(1 + t)*C[2]))/(18*(-7 + E^I)*(-5 + E^I)*(-1 + 5*E^I)* (-1 + 7*E^I)*E^(I*t)), 0]}} You can also specify initial conditions in your equations list. In[11]:= InputForm[RSolve[Join[eqns, {y[0]==2,z[0]==1}], {y[t],z[t]}, t]] Out[11]//InputForm= {{y[t] -> If[t >= 0, (252*I - (36*I)*E^I + (36*I)*E^(I + (2*I)*t) - (252*I)*E^((2*I)*(1 + t)) - 50*E^(I*(1 + t))*(-23 + 59*7^t - 12*t) + 7*E^(I*t)*(-23 + (59 - 36*I)*7^t - 12*t) + 7*E^(I*(2 + t))* (-23 + (59 + 36*I)*7^t - 12*t))/(18*(7 - 50*E^I + 7*E^(2*I))*E^(I*t)), 0], z[t] -> If[t >= 0, ((10080*I)*E^I - (3456*I)*E^(2*I) + (288*I)*E^(3*I) - (288*I)*E^(I + (2*I)*t) - (10080*I)*E^(3*I + (2*I)*t) + (3456*I)*E^((2*I)*(1 + t)) + 144*E^(I*(3 + t))*(-129 + (783 + 250*I)*5^t - (708 + 182*I)*7^t - 72*t) - 1370*E^(I*(2 + t))*(-43 + 261*5^t - 236*7^t - 24*t) - 35*E^(I*(4 + t))*(-43 + (261 + 144*I)*5^t - (236 + 144*I)*7^t - 24*t) - (144*I)*E^(I*(1 + t))*(-129*I + (250 + 783*I)*5^t - (182 + 708*I)*7^t - (72*I)*t) + 35*E^(I*t)*(43 - (261 - 144*I)*5^t + (236 - 144*I)*7^t + 24*t))/(18*(-7 + E^I)*(-5 + E^I)*(-1 + 5*E^I)*(-1 + 7*E^I)*E^(I*t)), 0]}} Daniel Lichtblau Wolfram Research
- References:
- Q: Solving econometric models
- From: "Mark S. Coleman" <mcoleman@bondspace.com>
- Q: Solving econometric models