MODEL

 

 

Introduction

The MODEL command is used to load model files (i.e., files with extension .frm, containing model equations). See at the bottom of this help file regarding equation syntax etc.

 

Please put a MODEL statement before READ statements: in that way all model variables not found in the databank will be auto-created when issuing the READ statement.

 

 

Syntax

MODEL filename ;

MODEL * ;

 

filename

The filename may include a local or global path.

*

If the filename is set to '*', you will be asked to choose the file in Windows Explorer.

 

Example

If the model file name is 'adam2.frm', you may load the file as follows:

 

MODEL adam2;

 

Note that extension '.frm' is automatically added if it is missing.

 

MODEL othermodels\adam3;

 

This will look for adam3.frm in the subfolder 'othermodels', relative the the Gekko working folder. When a model is loaded, it is first parsed. During this phase, you will get errors if parentheses are missing etc. Gekko will also warn against dublets (for instance two equations with the same left-hand side variable).

 

The MODEL statement also orders the equations, and compiles the model. The ordering splits the model into three parts: the prologue (pre-model), the simultaneous part, and the epilogue (post-model). So Gekko will automatically detect any pre- and post-model and will use this information in order to speed up simulations (hence, PCIM’s 'AFTER$' statement is ingnored if it is present in a model). The simultaneous part of the model is sub-divided into two parts: the feedback variables, and the simultaneous recursive variables. This information is used to speed up the Newton algorithm, by reducing the dimensionality of the simulteaneous equations.

 

After ordering, Gekko emits some files containing lists of exogenous, endogenous, and DJZ-type variables (that is, add-factors and variables used for exogenization). It also emits a file with ordering information. These files are assembled into a .zip-file with the name '[model]__info.zip', where [model] is the name of the model.

 

Model files (.frm files) consist of equations. A model may contain thousands of equations - there is no limit on this number other than available RAM. The equations have the following syntax (cf. also the GENR help file):

 

FRML frmlcode variable  = expression ;

 

frmlcode

May be used to indicate auto-generated D-, J- and Z-variables.

variable

A variable or an expression on a variable: log(var), dlog(var), dif(var) or pch(var)

expression

Any mathematical expression

You may use '$' instead of ';' at the end of the equation, but ';' is encouraged since '$' may be deprecated at some point.

 

An example to illustrate, we will consider a particularly simple equation:

 

FRML _GJDD Dif(y) = Dif(x) $

 

Ignoring for a moment the formula code, we first note that the equation uses the Dif() function, given as Dif(x) = x - x(-1). Hence, we get this equation:

 

FRML   y  =  y(-1) + x - x(-1) $

 

Next comes the formula code ('_GJDD'). This means that an add factor (JD) will be added, with the name JDy. So our equation is augmented into

 

FRML   y  =  y(-1) + x - x(-1) + JDy $

 

Last, exogenization dummies are added, too. This is done in order to ease exogenization of the equation, if needed. In general, such variables are add in the following way. Augmented with these, the equation becomes:

 

FRML   y  =  (1-Dy) * (y(-1) + x - x(-1) + JDy) + Dy * Zy $

 

As you can see, two variables are added, Dy and Zy. If Dy = 0, the two variables have no effect, but if Dy = 1, the equation reduces to y = Zy. I.e., the equations is given by the exogenous Z-variable Zy (or in other words, the variable y will always be set to this value, corresponding to exogenizing it). This is the equation used internally in Gekko. In addition to this equation, Gekko adds two more “reverted” equations regarding JRy1 and Zy1. These equations are not part of the "real" model, but are calculated after each simulation:

 

Reverted1: JDy = y - (y(-1) + x - x(-1)) $

Reverted2: Zy = y $

 

If Dy = 0, it is easy to see that JDy will not change its value (together with the above FRML, the first reverted equation reduces to JDy = JDy). But if Dy = 1, JDy will get the value that corresponds to what Zy might have been set to (JDy = Zy - (y(-1) + x - x(-1))). This way, you may set Dy = 1, and Zy to some chosen value. When you simulate, y will assume that value. Later on, you may reset Dy = 0 and simulate. You will notice that y still assumes the chosen value. So these exogenization dummies can be used to change the levels of endogenous variables, but keeping them endogenous if a multiplier is run on top of that.

 

The same functionality is often used for log-linear equations. Such an equation would look like:

 

FRML _GJRD Dlog(y) = Dlog(x) $

 

The add-factor (J-variable) is now relative (code ‘JR’), and the resulting equations become more complicated, but the basic idea is the same. See also the closely related GENR command.

 

 

Note

You may use broken lags, for instance x(-0.3). This is translated into 0.7*x + 0.3*x(-1). Leads (broken or unbroken) are allowed, too. For exponents, please use either 'a^b' or 'a**b' ('pow(a,b)' is also possible).

 

You may now put meta-information into the model file (.frm). As of now, Info, Date, and Signature fields are supported. Example (to be put in the top of the model (.frm) file):

 

// Info: Model used for forecasting 2012-2030

// Date: 7-11-2012 15:37:00

// Signature: fp88RzyZfJNaoTi3I4X3Ww

 

Gekko will complain if this format deviates, for instance the Info field is to be written with capital 'I', with no blank before the colon, and one blank after the colon. This rigorousness regarding form is to make it easy to spot the information in different .frm files. The Info and Date fields will be displayed when loading the model (MODEL command), and the Signature field is used for verifying that .frm files have not been changed relative to an 'official' version. The signature for a particular .frm file can be obtained with the SIGN command.

 

Related

options

 

 

OPTION folder model = [empty];

Related

commands

SIM, RES, EFTER, GENR, READ