# Building a table

I am having trouble building a table that looks similar to this: With the values of A = 1, δ = 0.05, α = 0.33, K0 = 1, and St is a random number between 0,1. T-1 means the previous period.

I have written the following code:

 With[{A = 1., \[Delta] = 0.05, \[Alpha] = 0.33},
NestList[Apply[
Function[{k, y, c, s, i},
With[{st = RandomReal[]}, {(1 - \[Delta]) k +
i, (k^\[Alpha] *A^(1 - \[Alpha])), st, (1 - s) y, s y}]]],
With[{st = RandomReal[]}, {1., 1., 1 - st, st, st}], 4]]]


My issue is that when I use the formulas to check if the output I find the they are not correct. I need some help on how to solve this issue, or if there is an easier way to do this. Any help is appreciated

Clear["Global*"]


Define the display format for indexed variables

(Format[#[t_]] := Subscript[#, t]) & /@ {k, i, y, s, c};


k is the only variable defined by a recurrence

k[0] = 1;
k[t_] := k[t] = (1 - δ) k[t - 1] + i[t - 1];


To reproduce the given results, the random values (s[t]) must be specified.

Evaluate[Array[s, 5, 0]] = {0.34, 0.95, 0.64, 0.42, 0.02};

y[t_] := k[t]^α a^(1 - α);
c[t_] := (1 - s[t]) y[t];
i[t_] := s[t] y[t]

a = 1; δ = 1/20; α = 33/100;

StringForm["", HoldForm[k[t] = (1 - δ) k["t-1"] + i["t-1"]]],
StringForm["", HoldForm[y[t] = k[t]^α a^(1 - α)]],
s[t], StringForm["", HoldForm[c[t] = (1 - s[t]) y[t]]],
StringForm["", HoldForm[i[t] = s[t] y[t]]]};

Join[{header}, Table[{t, k[t], y[t], s[t], c[t], i[t]}, {t, 0, 4}]] //
Grid[#, Dividers -> {Center, {2 -> True, 7 -> True}}] & //
NumberForm[#, {5, 2}] &


• Thanks! So to create a similar table but with actual random numbers I need to define s[t_]=RandomReal[]? Commented Apr 3, 2022 at 17:08
• Yes that would work Commented Apr 3, 2022 at 17:10
• When I define s[t_]=RandomReal[] the random number stays the same throughout. Is there a way to have different St at different T? Commented Apr 3, 2022 at 17:17
• Use SetDelayed := rather than Set = Commented Apr 3, 2022 at 17:19
• Amazing thank you very much kind sir :) Commented Apr 3, 2022 at 17:20
Clear["Global*"]
SeedRandom[1];
T = 4;
A = 1;
\[Delta] = 0.05;
\[Alpha] = 0.33;
k[0] = 1;
r := RandomReal[{0, 1}]


Equations:

y[0] = 1;
k[t_] := k[t] = (1 - \[Delta]) k[t - 1] + i[t - 1]
c[t_] := c[t] = (1 - sT[t]) y[t]
i[t_] := i[t] = sT[t] y[t]
y[t_] := y[t] = (k[t]^\[Alpha] A^(1 - \[Alpha]))
sT[t_] := sT[t] = r


Use the following, if you want to replicate the table in the OP (after disabling the corresponding code line above)

(* sT[0]=0.34;sT1=0.95; sT[2]=0.64; sT[3]=0.42; sT[4]=0.02; *)

Generating data:

data = Table[{t, k[t], y[t], sT[t], c[t], i[t]}, {t, 0, 4}]


Visualizing:

Grid[Prepend[
MapAt[Style[NumberForm[#, {5, 2}], 14, "BookAntiqua"] &,
data, {All, All}]
"\!$$\*SubscriptBox[\(K$$, \
$$t$$]\)=(1-\[Delta])\!$$\*SubscriptBox[\(K$$, $$t - \ 1$$]\)+\!$$\*SubscriptBox[\(I$$, $$t - 1$$]\)",
"\!$$\*SubscriptBox[\(Y$$, $$t$$]\)=(\!$$\*SubscriptBox[\(K$$, \
$$t$$]\)\!$$\*SuperscriptBox[\()$$, \
$$\[Alpha]$$]\)\!$$\*SuperscriptBox[\(A$$, $$1 - \[Alpha]$$]\)",
"\!$$\*SubscriptBox[\(s$$, $$t$$]\)",
"\!$$\*SubscriptBox[\(C$$, $$t$$]\)=(1-\!$$\*SubscriptBox[\(s$$, \
$$t$$]\))\!$$\*SubscriptBox[\(Y$$, $$t$$]\)",
"\!$$\*SubscriptBox[\(I$$, $$t$$]\)=\!$$\*SubscriptBox[\(s$$, $$t\$$]\)\!$$\*SubscriptBox[\(Y$$, $$t$$]\)"}]
, Dividers -> {
{False, {True}, False}
, {False, True, {False}, True}
}
, Alignment -> {{Center, {Center}}, {Center, Center}}
, Spacings -> {{1, 2, 2, 3, 4, 3}, 1}
]