Group Abstract Group Abstract

Message Boards Message Boards

0
|
85 Views
|
5 Replies
|
1 Total Like
View groups...
Share
Share this post:

Syntax error using RecurrenceTable function simulatin Stock-Flow Consistent model

See attached NB. A manipulate module using the RecurrenceTable function detects a syntax error which I have been unable to see. More eyes on what might be obvious to others might help.

POSTED BY: Lawrence Winkler
5 Replies
Posted 31 minutes ago

sanity check

ClearAll[y, yd, td, cd, hs, cs, gs, ts, hh, dHs, dHh];
eqns = {y[t] == cs[t] + gs[t],dHs[t] == hs[t] - hs[t - 1],dHh[t] == hh[t] - hh[t - 1],cs[t] == cd[t],gs[t] ==     gd[t],ts[t] == td[t],cd[t] == c1 * yd[t] + c2 * hh[t - 1],td[t] == \[Theta] * y[t - 1],yd[t] == y[t] - \[Theta] * y[t - 1],y[0] == 0, cs[0] == 0,yd[0] == 0, hh[0] == 0,hs[0] == 0, td[0] == 0, gs[0] == 0,gs[1] == g };(*all your recurrences*)
vars = {y, yd, td, cd, hs, cs, gs, ts, hh, dHs, dHh};
init = {y[0] == 0, cs[0] == 0, yd[0] == 0, hh[0] == 0, hs[0] == 0, td[0] == 0, gs[0] == 0, dHh[0] == 0, gs[1] == 20};
RecurrenceTable[Join[eqns, init], vars, {t, 1, 10}]

Still gives -

There are more dependent variables than equations, so the system is underdetermined.

So I rewrote it, think I got it correct (, but hope it helps).

ClearAll[y, taxes, yd, c, h, hg, g];
Manipulate[
 Module[{sim},
  sim =
   RecurrenceTable[{
     g[t] == Piecewise[{{g1, t <= switchTime}, {g2, t > switchTime}}],
     taxes[t] == taxRate y[t],
     yd[t] == y[t] - taxes[t],
     c[t] == income yd[t] + wealth h[t - 1],
     y[t] == c[t] + g[t],
     h[t] == h[t - 1] + yd[t] - c[t],
     hg[t] == hg[t - 1] + g[t] - taxes[t],
     h[0] == 0,
     hg[0] == 0},
    {y, c, yd, taxes, h, hg, g},
    {t, 1, periods}];
  ListLinePlot[
   sim[[All, #]] & /@ {1, 2, 5, 7},
   PlotLegends -> {"y", "c", "h", "g"},
   PlotRange -> All,
   AxesLabel -> {"Time", "Value"},
   ImageSize -> Large]]
 , {{g1, 20, "initial g"}, 1, 30, 1, Appearance -> "Labeled"},
      {{g2, 30, "new g"}, 1, 50, 1, Appearance -> "Labeled"},
      {{taxRate, 0.2, "tax rate \[Theta]"}, 0., 1., 0.05, 
  Appearance -> "Labeled"},
      {{income, 0.6, "income \[Alpha]1"}, 0., 0.99, 0.05, 
  Appearance -> "Labeled"},
      {{wealth, 0.4, "wealth \[Alpha]2"}, 0., 1., 0.05, 
  Appearance -> "Labeled"},
      {{switchTime, 20, "switch time"}, 1, 49, 1, 
  Appearance -> "Labeled"}, {{periods, 50, "periods"}, 20, 100, 1, 
  Appearance -> "Labeled"}]
POSTED BY: Karl Fraser

I fixed most errors but still have issues.

The key is: I want to use RecurrenceTable (and other functions) to simulate the models in Monetary Economics by Wynne Godley, et al. These models define what is called Stock-flow consistent models. The Levy economic institute, part of Bard College, which is associated with Columbia University continue to research this area.

From what I've seen, there are packaged solutions in R (and some other modeling systems like EViews) simulate these models using the typical array and do loop constructions which, in my mind, hide the basic models behind these constructs, or are black-boxes. It seems like Mathematica should be able to simulate these models with relative ease using RecurrenceTable.

I've cleaned up some of the coding thus far, but still mathematica is unhappy with the result.

In this latest interation, Mathematica results in dumping some RecurrenceTable without generating a computation. (and giving no reason for its failure).

Attachments:
POSTED BY: Lawrence Winkler

Thanks to all. I haven't been using Show Expression. This gives me some critical information I haven't used before, not only this issue but some from past modules where I fat-fingered some entry.

POSTED BY: Lawrence Winkler
Posted 2 days ago

Hello,

Looking VERY closely at the ClearAll line, one can see that comma after gd is smaller than the other commas. If you use Show Expression from Cell Menu, you see the offending section as:

RowBox[{
    SubscriptBox["g", 
     RowBox[{"d", ",", " "}]],

Clearly there is a corruption after the gs Subscript and in the gd Subscript.

The small comma is part of the Subscript, so delete it and add the comma after the Subscript.

POSTED BY: Karl Fraser

You use g as a function in RecurrenceTable and as a number in Manipulate. I tried this:

RecurrenceTable[{y[t] == Subscript[c, s][t] + Subscript[g, s][t], 
    Subscript[\[CapitalDelta]h, s][t] == 
     Subscript[h, s][t] - Subscript[h, s][t - 1], 
    Subscript[\[CapitalDelta]h, h][t] == 
     Subscript[h, h][t] - Subscript[h, h][t - 1], 
    Subscript[c, s][t] == Subscript[c, d][t], 
    Subscript[g, s][t] == Subscript[g, d][t], 
    Subscript[c, d][t] == c1 yd[t] + c2 Subscript[h, h][t - 1], 
    td[t] == \[Theta] y[t - 1], yd[t] == y[t] - \[Theta] y[t - 1], 
    y[0] == 0, Subscript[c, s][0] == 0, yd[0] == 0, 
    Subscript[h, h][0] == 0, Subscript[h, s][0] == 0, 
    td[0] == 0} /. {Subscript[g, s] -> g, \[Theta] -> taxRate, 
    c1 -> consumeRate, c2 -> overspend} /. {taxRate -> 1, 
   consumeRate -> 1, overspend -> 1}, {g, td, y, yd, Subscript[c, d], 
  Subscript[c, s], Subscript[g, d], Subscript[h, h], Subscript[h, s], 
  Subscript[\[CapitalDelta]h, h], Subscript[\[CapitalDelta]h, s]},
 {t, 1, 50}]

and it gives this warning:

RecurrenceTable::underdet: There are more dependent variables than equations, so the system is underdetermined.
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard