BLOCK

<< Click to Display Table of Contents >>

Navigation:  Gekko User Manual > Gekko statements >

BLOCK

Previous pageReturn to chapter overviewNext page

Four types of options

Gekko operates with four types of options: global options, general options, block-options and local options. Global options are read when Gekko launches and cannot be altered later on (they have the form option global ...). General options are stated with the OPTION command and apply until changed. Block options are stated with the BLOCK command and apply for a block of Gekko statements. Local options are stated inside the <> local option field and apply to that single statement only. See more here.

 

A BLOCK structure is used to set the time period and/or other options temporarily (block options). A block can for instance be used inside a function or procedure definition, where the time period, frequency or other options may be changed, but where these changes should be undone after leaving the function/procedure. A block could be used together with LOCAL variables to avoid changing the state of the program when calling a function/procedure.

 

Using a block series dyn = yes; ... ; end; is the only way to set the <dyn> option on several expressions at the same time. This is because option series dyn should only be used when needed, that is, for expressions like = x[-1] + 1; and similar. So using the option together with a BLOCK makes sure the option is turned off again.

 


 

Syntax

 

block option1, option2, ...;

 ...statements...

 ...statements...

 ...statements...

end;

 

option

Can be one of two kinds:

 

A time period, using the TIME keyword, for instance block time 2020 2030; ... ; end; This corresponds to time 2020 2030;.

An option setting (OPTION statement without the option keyword), for instance block freq q; ... ; end; to change the frequency, corresponding to option freq q;.

 

The options (including time period) can separated with commas, for instance block freq q, time 2020q1 2025q4, print width = 200;. The BLOCK keyword must always be ended with an END.

 

 


 

Examples

 

The following is an example of nested blocks that set the time period

 

time 2001 2003;
block time 2011 2013; 
  y1 = 100;             //y1: 2011-13
  block time 2021 2023; 
    y2 = 100;           //y2: 2021-23
  end; 
  y3 = 100;             //y3: 2011-13
  end; 
y4 = 100;               //y4: 2001-2003

 

This is an example of setting two options for printing (corresponding to option print fields ndec = 1; option print fields pdec = 1;).

 

time 2001 2003;
y1 = 1.17y1 <2002 2003> %= 1.27, 1.37;
block print fields ndec = 1, print fields pdec = 1; 
  prt y1;  //printed with 1 decimal
end; 
prt y1;    //printed with default decimals
 
//  Result:
//                   y1         % 
//  2001            1.2         M 
//  2002            1.2       1.3 
//  2003            1.2       1.4 
// 
//                   y1         % 
//  2001         1.1700         M 
//  2002         1.1849      1.27 
//  2003         1.2011      1.37 

 

BLOCK can also be used to change frequency temporarily. The following example will create the quarterly series y1!q defined over 2001q3-2023q2. After the BLOCK, the time period will be back to annual 2021-23, therefore y2!a is defined over these three years.

 

reset; 
time 2021 2023; 
block freq = q, time 2021q3 2023q2; 
  y1 = 100; 
end;
y2 = 100;
prt <n> y1!q, y2;  //y2 same as y2!a, since we are back at annual frequency;

 

 


 

Note

 

A designated time period does not have to be the first item in a list of block options.

 


 

Related statements

 

LOCAL, OPTION, TIME