Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

New to mathematica, trying to use Eric Swanson's Pertubation AIM program to solve DSGE models. His code produces a solution as a list or a table. My question is how do I use this list to simulate the model without copying and pasting stuff? For the one sector stochastic growth model, the solution (as a list) appears as:

{A == 0.800000000000000 A[-1 + t] + 1.00000000000000 eps, 
C == 0.1114834992288968 + 0.292723851887318 A[-1 + t] + 
0.1186384419679934 Inv[-1 + t] + 0.447062121415789 K[-1 + t] + 
0.365904814859147 eps, 
Inv == 
0.4186970784697240 + 0.902059574107021 A[-1 + t] - 
0.0225290917630828 Inv[-1 + t] - 0.0848957841160119 K[-1 + t] + 
1.12757446763378 eps, 
K == 1.431977509390795 + 0.238836154208396 Inv[-1 + t] + 
0.900000000000000 K[-1 + t], 
r == 0.01010101010101003 + 0.0880808080808080 A[-1 + t] - 
0.01840727127888952 Inv[-1 + t] - 0.0693636363636363 K[-1 + t] + 
0.110101010101010 eps, 
Welf == -988.913562642210 + 5.22803270579111 A[-1 + t] + 
0.893524510010050 Inv[-1 + t] + 3.36704491694070 K[-1 + t] + 
6.53504088223889 eps, 
Y == 0.4295932528172384 + 0.800000000000000 A[-1 + t] + 
0.0716508462625189 Inv[-1 + t] + 0.270000000000000 K[-1 + t] + 
1.00000000000000 eps}

All variables except investment (Inv) are in logs. eps is the technology shock (i.e., A=0.8*A[t-1]+eps where A is log total factor productivity). I also have a list of steady state values {0, 0.1114834992288968, 0.4186970784697240, 1.431977509390795, \ 0.01010101010101003, -988.913562642210, 0.4295932528172384}.

So my question is, given these lists, how do I assign the steady state as starting values for the model, assign a random sequence to eps, and simulate the model?

share|improve this question
To make your question more accessible to other users you should provide more information about what you are trying to do. Not everyone is familiar with the topic. I also would suggest to have a look at the tutorials in Mathematica on modelling (e.g. [reference.wolfram.com/mathematica/guide/…). –  g3kk0 Jul 28 '13 at 21:05
add comment

1 Answer

I'm not going to give you the complete code, as I'm not actually near a machine with Mathematica on it. I'd suggest you convert the coefficients into matrix or vector form using Coefficient and then used FoldList to simulate it. Bearing in mind I'm typing from memory, you'd do something like

coefmat = {Coefficient[#,A[t-1]],Coefficient[#,C[t-1]],Coefficient[#,Inv[t-1]],
 Coefficient[#,Y[t-1]]}/@ (Rest /@ eqns);
epscoefvec = Coefficient[#,eps]& (Rest/@eqns)

I am using Rest/@eqns to get the right hand side of the equations, which I assumed you named in getting your output. There are fancier ways to do this using Thread but I don't trust my ability to type that kind of approach from memory without testing the code.

As an aside I would note that is it not good practice to used single Capital letters for symbols in Mathematica as they can clash with the program's own built-in symbols. C and K are both issues here. I'm not sure why you aren't using lower case symbols anyway, since your variables are in logs, and lower case for logs is normal notation in economics.

You can then use these coefficients to simulate your system. Assuming you called the steady state vector something like stst, you can now use FoldList like this:

result = FoldList[coefmat #1 + epscoefvec #2 &, stst, 
          RandomVariate[NormalDistribution[0,1], 100] ]

Note that I am using standard normal shocks (rather than the autocorrelated shocks often used in DSGEs to assume the dynamics instead of generate them - I'm an economist and you can probably guess not a real business cycle fan ;)), and assuming you have Mathematica version 9. If you have an earlier version the syntax to generate vectors of random numbers will be a little different.

You might be unfamiliar with some of the symbols I have used, if you are new to Mathematica. If so, have a look at the documentation for Map, Slot and tutorials on functional programming.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.