<< Click to Display Table of Contents >> Assignments and types |
![]() ![]() ![]() |
Assignments are of the form ... = ... ; with a = symbol, for instance y = 2 * x;, %y = 2 * %x;, #m = a, b;, and so on. So the right-hand side (RHS) expression is assigned to the left-hand side (LHS) variable. There may also be a type indicator, like SERIES y = 2 * x;, stating that y should become a series type. There are the following type indicators:
•series: SERIES y = ...;
•val: VAL %y = ...;
•date: DATE %y = ...;
•string: STRING %y = ...;
•list: LIST #y = ...;
•map: MAP #y = ...;
•matrix: MATRIX #y = ...;
•var: y = ...; or %y = ...; or #y = ...; or VAR y = ...; or VAR %y = ...; or VAR #y = ...;
•Note that var type in the descriptions below include the common case where the type is not explicitly stated.
•In the following, LHS means left-hand side
•In the following, RHS means right-hand side
There are the following rules regarding assignments.
LHS name starts with % symbol (scalar).
•Fails if there is LHS type indicator and this is not val, date, string or var type.
•%y = ...timeless...;. The RHS is a timeless series. If the LHS type is val or var, the LHS becomes a val with the value of the timeless series.
•%y = ...val...;. The RHS is a val. If the LHS type is val or var, the LHS becomes the RHS val. If the LHS type is a date, Gekko tries to convert the val into a date (for instance, 2020 into 2020a).
•%y = ...string...;. The RHS is a string. If the LHS type is string or var, the LHS becomes the RHS string.
•%y = ...date...;. The RHS is a date. If the LHS type is date or var, the LHS becomes the RHS date. If the LHS type is a date, Gekko tries to convert the val into a date (for instance, 2020 into 2020a).
•%y = ...1x1 matrix...;. The RHS is a 1x1 matrix. If the LHS type is val or var, the LHS becomes the RHS matrix element.
Left-hand side name starts with # symbol (collection).
•Fails if there is LHS type indicator and this is not list, map or matrix.
•matrix #y = ...series...;. The RHS is a normal series. If the LHS type is matrix, the LHS becomes a matrix corresponding to the values inside the series. If the RHS is a timeless series, and the LHS type is matrix, the LHS becomes a matrix corresponding to the value inside the series (duplicated for each period in the current time period). If the type is not stated, for instance #y = a;, Gekko will not auto-convert the series a into a list of values #y (this could create confusion in relation to naked list definitions).
•#y = ...list...;. The RHS is a list. If the LHS type is list or var, the LHS becomes a list corresponding to the RHS list.
•#y = ...map...;. The RHS is a map. If the LHS type is map or var, the LHS becomes a map corresponding to the RHS map.
•#y = ...matrix...;. The RHS is a matrix. If the LHS type is matrix or var, the LHS becomes a matrix corresponding to the RHS matrix.
Left-hand side does not start with % or # symbol (series).
•Fails if there is LHS type indicator and this is not series
•y = ...series...;. The RHS is a series. If the LHS type is series or var, the LHS becomes a series corresponding to the RHS series (frequencies must conform).
•y = ...val...;. The RHS is a val. The val is duplicated into all of the series observations.
•y = ...list...;. The RHS is a list. The list elements are put into the series observations (the list elements must be of val type, and if the last list element is stated with rep *, the list is expanded to fit with the time period).
•y = ...1x1 matrix...;. The RHS is a 1x1 matrix. The matrix element is duplicated into all of the series observations.
•y = ...nx1 matrix...;. The RHS is a nx1 matrix. If the size of the matrix fits the time period, the matrix elements are put into the series observations.
Note in general that when assigning variables, the left-hand side is always assigned to a copy of the right-hand side (pass by value, not pass by reference).