Add-factors etc.

<< Click to Display Table of Contents >>

Navigation:  Gekko User Guide > Modeling User Guide >

Add-factors etc.

Previous pageReturn to chapter overviewNext page

In order to follow the examples, you must first download the model and databank (click demo.zip and copy the two files gekko.frm and gekko.gbk into your Gekko working folder). Next start up Gekko in the working folder, and type:

 

(See the bottom of this page for the full code).

 

restart;
mode sim;
time 2017 2040;

 

This clears up the workspace, and sets the global time period (for which we will later simulate the model). Next, issue these statements, in order to run the baseline simulation with 0% growth in government consumption.

 

model gekko;
read gekko;
%= 0;
sim;
clone;

 

Gekko auto-creates add-factors depending on formula codes. Imagine some stochastic shock on the net exports (e) in 2017. The e-equation has equation code _GJ. You may read more about such codes in the MODEL help file, but suffice to say that the code means that the equation in reality reads:

 

FRML _GJD        dif(x) = -0.2*(y[-2] - 500);                     //original
                      x = x[-1] - 0.* (y[-2] - 500) + JDx;      //result

 

Note the add-factor JDx, and note also that the left-side dif()-function has also been resolved. This latter equation is the one that Gekko actually simulates, and these "detailed" equations can be shown by means of the DISP statement:

 

disp x;

 

Try click Show detailed equation, in order to see the "full" equation. So even though the variable JDx is not directly seen in simple.frm, it exists as a hidden exogenous variable on the right-hand side of the x-equation. When simulating, the value is automatically set to 0 if no other value is given.

 

Now, we may try to change the add-factor in the year 2017 (i.e., a temporary shock), simulate and plot the result:

 

jdx <2017 2017> += 100;
sim;
plot <2016 2040 m> y, c, x, g;

 

clip0192

 

In the first two periods (2017 and 2018), net exports x are augmented by 100, since the two period lagged y does not begin to affect the equation before 2019. (Since the equation is a difference equation (with dif(x) on the left side), augmenting the add-factor in one year works the same way as augmenting an add-factor permanently in a non-difference equation).

 

It is seen that there are no long-run effects — in the long run all effects are 0. So temporary shocks on net exports only creates temporary fluctuations, but these are still quite significant due to amplification via the Keynesian multiplier effect.

 

Gekko contains some more advanced possibilites regarding add-factors and formula codes. The c equation has equation code _GJ_D, i.e. there is a D in the 5th position. This implies that three variables are created: Dc, Jc, and Zc.The "full" c-equation is this: = (0.6*+ 0.1*c[-1] + Jc) * (1-Dc) + Dc*Zc. The variables Dc and Zc can be used to exogenize an equation. If Dc is set to 1, the equation will reduce to = Zc, so that Zc can be used to set the target for c. See also the last part of the MODEL help page.

 

 

The full code

 

restart;
mode sim;
time 2017 2040;
model gekko;
read gekko;
%= 0;
sim;
clone;
disp x;
jdx <2017 2017> += 100;
sim;
plot <2016 2040 m> y, c, x, g;