TABLE

<< Click to Display Table of Contents >>

Navigation:  Gekko User Manual > Gekko statements >

TABLE

Previous pageReturn to chapter overviewNext page

The TABLE statement is used to call tables (.gtb files) designed in a special XML format. This format is designed for ease of use regarding most types of tables with the time dimension running outwards, and different variables running downwards.

 

Guide: tables

For an easier introductory guide on Gekko tables, see this page.

 

Table output can be either text or html. The latter is default since it often provides more readable output. When a table (text or html) has been printed, you may use the 'Copy' button to copy the cells to the clipboard, for successive pasting into e.g. a spreadsheet like Excel. Copying the table this way includes full precision of all numbers, but formatting will be lost.

 

For html tables shown in the 'Menu' tab in the Gekko window, the user may click the link 'Transform options' to transform the data (for instance, percentage growth).

 

Tables can also be called from menus (see MENU).

 

Note that you may use scalar-variables (for instance strings) inside the xml elements. If you want to insert a scalar into a text field, enclose the scalar in {}-curlies, for instance <txt>Table regarding the year {%year}</txt>.

 

Note: You may use the in-built XML Notepad editor to edit the .gtb file, cf. the XEDIT statement.

 


 

Syntax

 

table < period operator  HTML  WINDOW=main > tablename ;

 

period

(Optional). Time period.

operator

(Optional). Can be m for multiplier or r for Ref (reference) databank. The m code works as if two tables were subtracted, one made with no operator ('Work'), and one made with r operator (Ref). No other codes are possible at the moment (operator n can also be used, but is the same as omitting an operator).

HTML

(Optional). If html is indicated, the table will be printed in html format, instead of in text format. It will be shown in the 'Menu' tab (unless the WINDOW=main option is active).

WINDOW=

(Optional). If WINDOW=main is indicated, output will be put into the main window, even if the table is of html type. In that case, html codes will be printed on the screen. This can be used together with pipe<html>, in order to insert a html table inside a html file. You may use TELL to insert other html lines into the html file.

tablename

Name of the table to be printed (extension .gtb can be omitted)

 

If no period is given inside the <...> angle brackets, the global period is used (cf. TIME).

 

The Gekko table system can be used in two ways: either via a simple XML syntax to describe the appearance of the tables, or via a more matrix-like syntax where the tables' elements are assigned one by one (like filling in a matrix). For most tables with time running horizontally and variables vertically, the XML syntax is much easier to use.

 

Example:

 

Table printed: 30-04-2018 14:53:30
----------------------------------------------------------------------------------------
| Table 1. Supply balance, Million DKK, current prices                                 |
--------------------+-------------------------------------------------------------------
|                   |      2005       2006       2007       2008       2009       2010 |
--------------------+-------------------------------------------------------------------
| GDP             Y |   1554520    1605530    1676300    1734800    1796410    1849360 |
| Imports         M |    674748     716544     748044     771898     802542     806695 |
| Total (Y+M)   Yst |   2229270    2322080    2424340    2506700    2598950    2656050 |
--------------------+-------------------------------------------------------------------

 

In this table (shown in text format), there is a column with descriptions ('GDP' etc.), followed by a column with variable names ('Y' etc.). The table can easily be constructed by means of XML syntax. The XML tables use syntax that resemble the way tables are made in HTML syntax, specifically the use of the colspan attribute to merge cells horizontally. Data-columns (for instance the period 2005-10 above) are conceptually treated as a single (expandable) column, and formatting can be set on many levels.

 

To start out with a concrete example, the above table was constructed by means of the following code:

 

<?xml version="1.0" encoding="Windows-1252"?>
<gekkotable>
  <tableversion>1.0</tableversion>
  <table varformat="f9.0">
    <cols>
      <colborder/>
      <col txtalign="left"/>
      <col txtalign="right"/>
      <colborder/>
      <col type="expand" txtalign="center"/>
      <colborder/>
    </cols>
    <rows>
      <rowborder/>
      <row>
        <txt colspan="3">Table 1. Supply balance, Million DKK, current prices</txt>
      </row>
      <rowborder/>
      <row>
        <txt/>
        <txt/>
        <date/>
      </row>
      <rowborder/>
      <row>
        <txt>GDP</txt>
        <txt>$</txt>
        <var>Y</var>
      </row>
      <row>
        <txt>Imports</txt>
        <txt>$</txt>
        <var>M</var>
      </row>
      <row>
        <txt>Samlet tilgang (Y+M)</txt>
        <txt>$</txt>
        <var>Yst</var>
      </row>
      <rowborder/>
    </rows>
  </table>
</gekkotable>

 

Inside the <table> tag (where the real defining of the table begins), the columns are first defined inside the <cols> tag. You may visualize the above table as the following 3-column table:

 

  ==========  | ====== | ========
    COL1      |  COL2  |   COL3  
  ==========  | ====== | ========
              |        |
-----------------------------------
| Heading spanning 3 columns....  |
-----------------------+-----------
|                      |  Periods |
-----------------------+-----------
| Description1    var1 |  Data    |
| Description2    var2 |  Data    |
| Description2    var3 |  Data    |
-----------------------+-----------

 

In the XML defintion above, inside the <cols> tag, the columns are defined. First there is a <colborder>, corresponding to the left table border. Next there is a <col> tag, with default text alignment set to left, followed by a similar tag with text alignment set to right. These correspond to the "description" and "variable name" columns in the table. Next, there is a <colborder> to separate descriptions/variable names from the data, followed by a <col> of type expand. This column is expandable, and expands into as many columns as there are time periods. The <cols> definitions end with a <colborder>, corresponding to the right table border.

 

Regarding the <rows>, these are given one by one by means of <row> tags. Each <row> expects 3 items, since there are 3 columns defined in the <cols> section. The first item in <rows> is a <rowborder>, however, so these are added analogously to the <colborders> under the <cols> tag. The first <rowborder> corresponds to the top table border, and the next item is a <row> with a <txt> item inside. The <txt> spans all 3 colums, so the vertical border between column 2 and 3 will be hidden in this row. Next, there is a <rowboarder>, and then the date row begins. This row is filled with two empty <txt> items (think of these ase placeholders), and then a <date> tag corresponding to the third column. This puts dates corresponding to the time period into this section of the table. Afterwards, there is a <rowborder>.

 

Next is variables, and these are given by means of two <txt> tags and one <var> tag. The <txt> tags put text into the description and variable name fields, and the <var> tag identifies the variable (or expression) to print out. So we have these tags regarding the first variable row:

 

<txt>GDP</txt>
<txt>$</txt>
<var>Y</var>

 

The $ is a special code implying that this piece of text is to be taken from the following <var> field. The text could alternatively have been given by means of <txt>Y</txt>, but this way of doing it would produce a lot of duplicate variable names in the file. To avoid duplication (and reduce the error rate when editing variable names), it is convenient to use the $-codes. The two next rows are added in a similar fashion, and finally a <rowborder> tag concludes the table.

 

It should be noted that there are three different item types: <txt>, <var> and <date>. These are formatted differently, and to format them you may use attributes corresponding to the type, for instance varformat, varalign, or txtalign. Such attributes are inherited, and can be put on different levels of the table, more specifically on the following tags (in that order):

 

in <table> (applies to the whole table).

in <col> (applies to the specific column>.

in <rowformat> (applies to all following rows, until next <rowformat> overrides it).

in <row> (applies to the specific row)

or in the element itself (for instance in the <txt> or <var> tags).

 

For instance, in the example there is the following format given: <table varformat="f9.0"> .This applies to the whole table (since there are no other varformats in the table), and it means that variables are to be written with a width of 9 characters, and without any decimals. Lower level formats override higher levels, so for instance a specific row might be formatted differently. For instance <row varformat="f9.2"> could be used if that particular row were a percent change, where two decimals might be the most desirable format.

 

Regarding borders, parts of these can be hidden in different ways. The easiest way is to use column spanning, as in the example above. Since the table heading ("Table 1. Supply balance") spans three columns, the inner vertical border after the second column is not shown. To remove all vertical borders for a particular row (or successive rows), you may use the tag <colborderhide> inside the <rows> tag. This will remove all vertical borders for the following rows, until a <colbordershow> is set. To remove only specific borders, you may use <colboderhide>inner<colborderhide>, or <colboderhide>outer<colborderhide> (this hides inner or outer borders). You may also indicate the borders to remove by means of a comma-separated list of integers: <colboderhide>1,2<colborderhide>. This will hide the first and second vertical borders.

 

List of different tags and attributes

 

In general, the tags (for instance <txt>) can be thought of as contaning data, whereas the attributes (for instance txtalign="left") can be thought of as containing formatting. So the tags, or more precisely the elements inside the tags (for instance the element GDP in <txt>GDP</txt>) can be thought of as the content of the table, whereas the attributes describe how the content is formatted/shown.

 

Tags:

 

<col>: defines a column: set attribute type="expand" for data columns. You may define a special kind of column showing only one (indicated) period.

<colborder>: defines a vertical border separating columns

<colborderhide>: hides vertical borders, content can be "inner", "outer", or list of integers

<colbordershow>: shows vertical borders (if some of them have been hidden)

<cols>: inside this tag, columns are defined one by one, including their type, and any borders separating them

<row>: indicates a new row, content is defined inside the <row>

<rowborder>: indicates a horizontal border

<rowformat>: sets format that is to apply to all rows until next <rowformat>

<rows>: inside this tag, rows are defined one by one, including horizontal borders etc.

<subcolborder>: is used to show (grey) borders between columns inside a time period. This tag is set inside a <col> tag. Example: <subcolborder period="%per1"/> or <subcolborder period="2030"/>.

 

Attributes:

 

colspan (example: colspan="2"), used inside a <row> tag to span/merge columns. Similar to the way cells are merged horizontally in HTML tables. Note that code like <text colspan="3">AAA</txt> <txt>BBB</txt> would make 'BBB' appear in the fourth column, so the <text colspan="3"> tag really represents three <txt> tags.

datealign (left/middle/right): used inside <table>, <col>, <rowformat>, <row>, or <date>. Horizontal alignment of dates in a <date> tag.

period (example period="#target_year"). Used inside a <col> tag to indicate that only that particular period is to be shown, regardless of other time settings. Handy for a column with special kinds of indicators etc. The attribute is also used inside <subcolborder>, to indicate the period after which a gray line is to be inserted. Example: <col period="#target_year" txtalign="center" varformat="f8.3"/>.

txtalign (left/middle/right): used inside <table>, <col>, <rowformat>, <row>, or <txt>. Horizontal alignment of text in a <txt> tag.

type (example: type="span"): used inside a <col> tag to indicate that it is expandable (for instance data columns). Only columns of "expand" type are allowed to auto-expand into more columns, corresponding to the number of time periods the table is called with.

vardisplay (example: vardisplay="p"): used inside <table>, <col>, <rowformat>, <row>, or <var>. Sets operator regarding <var> tag. These should be given as Gekko operators, for instance "p" for percent growth rate, "q" for multiplier percentage difference, "n" for levels etc (cf. the PRT/PLOT/SHEET statements).

varformat (example: varformat="f12.2"): used inside <table>, <col>, <rowformat>, <row>, or <var>. Sets the print format for <var> tags. For instance, "f12.2" means floating point, width = 12 characters, and 2 decimals. Integers (no decimals) can be set as for instance "f12.0". If you need to round off to, for instance, the nearest hundreds, you may use negative decimals places, for instance varformat = "f9.-2". A number like 12345 would then be printed as 12300.

varscale (example: varscale="0.001"): used inside <table>, <col>, <rowformat>, <row>, or <var>. All data in the given context is scaled/multiplied by the value given.

 

 

Editing the table

 

It is recommended that you use the in-built XML Notepad editor to edit the XML files, cf. the XEDIT statement (if used, choose 'View' --> 'Expand All' to unfold all XML nodes). You may also use Notepad (cf. the EDIT statement), but it is recommended to use a specific XML editor for editing the tables. Using a simple text editor like Notepad entails some potential problems. There will be no check that the XML syntax is correct, e.g. that a tag like <row> is always closed by means of a corresponding </row> tag. Also, the XML syntax represents some characters in a special way: notably the < , >, and & characters (these should be written &lt;, &gt;, and &amp;).

 

If the file is not in valid XML syntax, Gekko will complain that the file is invalid and abort.Internally, when executing a XML table, the XML is translated into "normal" Gekko code (heavily using table objects) which is then executed in the same way as a normal Gekko program file.

 

 


 

Example

 

Call the table table1.gtb, for the annual period 2012-2016:

 

table <2012 2016> table1;

 

To have it printed in HTML instead, and as multiplier differences (operator m), use:

 

table <2012 2016 m html> table1;

 

To edit the .gtb file using Notepad, you may use edit table1.gtb;, but it is preferable to use a dedicated xml editor, which can be called with XEDIT:

 

xedit table1.gtb;

 

 


 

Note

 

In order to copy-paste a html table to Excel, the most reliable way is to use the copy-button in the Gekko user interface. There is an option to paste decimal separators as commas instead of periods (option interface clipboard decimalseparator). Alternatively, you may right-click the html-table and paste from that menu, but that way you will lose non-shown decimals in the table cells.

 

In html tables, if you hover over a number, a label will appear with full decimals.

 

Gekko will look for the table in first the working folder, and then in the folders denoted with option folder table, option folder table1 and option folder table2 (in that order). If the table is called from a .html menu, the URL path of the table call will be included too (after option folder table2). So if preferred for menu systems, you may put your table (.gtb) files next to your menu (.html) files.

 

The function frombank() can be used to decorate a table with filename/date of the underlying databank.

 

If you need to insert blank spaces in <txt>-fields in a html table (for instance to manually control the width of a column), you can use the special xml-code &amp;nbsp; (if written in a text editor like Notepad), for instance three blanks: <txt>Gdp&amp;nbsp;&amp;nbsp;&amp;nbsp;</txt>. If the code is written via XEDIT, you should write the code as &nbsp;. These special codes will only work for html tables: for txt tables they will show up as noise. For txt tables, you can just use normal blanks, for instance: <txt>Gdp   </txt>.

 

If a variable is missing, and if option table ignoremissingvars = yes (default), the values will be shown as missings ('M'), instead of Gekko reporting an error. You can use a TIMEFILTER to omit periods for a more readable table.

 

There is an automatic table conversion tool from the older PCIM table format to the new XML format. See the menu: 'Utilities' --> 'Converters' --> 'PCIM converters' --> 'Convert PCIM tables...'.

 

 


 

Related options

 

option folder table = '';
option folder table1 = '';
option folder table2 = '';
option interface table operators = yes;
option table decimalseparator = period;
option table html datawidth = 5.5;
option table html firstcolwidth = 5.5;
option table html font = Arial;
option table html fontsize = 72.0;
option table html secondcolwidth = 5.5;
option table html specialminus = no;
option table ignoremissingvars = yes;
option table mdateformat = '';
option table stamp = yes;
option table thousandsseparator = no;
option table type = html;

 


 

Related statements

 

EDIT, MENU, PLOT, XEDIT