EXPORT

<< Click to Display Table of Contents >>

Navigation:  Gekko User Manual > Gekko statements >

EXPORT

Previous pageReturn to chapter overviewNext page

The statement writes the first-position databank or specific variables to a non-gbk file in a particular format. Use WRITE to write to a .gbk file. Please note that the EXPORT formats currently only supports series (or a matrix), not other variable types (you may use WRITE to store these in .gbk files).

 

Compatibility note: If a time period is not indicated in the <>-option field, Gekko 3.0 will only export data inside the global time period. Before Gekko 3.0, all data would have been exported. To emulate previous behavior, you can use EXPORT<all>. Alternatively, you may set "OPTION bugfix import export = yes;". If the option is set, IMPORT and EXPORT will work as in pre-3.0 versions. The option will be removed at some point, so it is better to change occurrences of date-less EXPORT to EXPORT<all> in old Gekko program files.

 

Excel note: When exporting xlsx files, if you encounter "dates" with integer numbers larger than 20000, this may be because Excel shows the dates as numbers rather than dates. You may try to change the format of the date cells: right-click, "Format cells", "Date".

 

There is the following equivalence between EXPORT and WRITE: EXPORT = WRITE<respect>, and the inverse: WRITE = EXPORT<all>. If a local period is used, like export <1980 2020>, EXPORT and WRITE behave in the same way.

 

 


 

Syntax

 

export < period format  ALL  CAPS=...  COLS DATEFORMAT=...  DATETYPE=... OP=... >  filename ;
export < period format  ALL  CAPS=...  COLS DATEFORMAT=...  DATETYPE=... OP=... >  variables  TO  variables FILE=filename ;

 

period

(Optional). Without a time period indicated, Gekko will write all the data for all observations. When a period is indicated, the written data(bank) is truncated.

format

File format. Choose between ARROW, CSV, FLAT, GCM, GDX, GNUPLOT, PRN, PYTHON, R, TSD, TSP, XLS/XLSX (regarding gbk, see the WRITE statement).

ARROW: The Apache Arrow format, see the examples under R_RUN or PYTHON_RUN. IMPORT<arrow> does not work yet, but will soon.

CSV: Only frequencies matching the current frequency setting will be written.

FLAT: This is a special Gekko text-based format with lines that resemble series statements. See more details in the IMPORT section.

GCM: This will export series as Gekko SERIES statements. You can use operators n, d, p, m or q, for instance export<gcm op=p> {#vars} file=data; to put the percentage change in the #vars timeseries into the file data.gcm. Alternatively, you may use ^=, %=, += or *= operators,  for instance export<gcm op='%='> {#vars} file=data;. With the latter operators, you must enclose them in single quotes ('). You may use export<gcm> to export in levels (corresponding to operator n). A .gcm file is imported simply with RUN. See the FLAT format for a faster version of this format.

GDX: A binary GAMS-database. Note "OPTION gams exe folder = ..." where it is possible to point to the exact GAMS folder (otherwise the system will try to auto-locate GAMS). It seems necessary to use a 32-bit version of GAMS, since the current version of Gekko is 32-bit. Please note that only array-timeseries (see SERIES) are written to the .gdx file, and that Gekko does not (at the moment) export timeless timeseries. GAMS can be freely downloaded as a demo, and the demo will work fine regarding Gekko EXPORT.

GNUPLOT: Gekko writes a prn-like format suitable for gnuplot.  If no period is set, Gekko will write all years occurring in the first-position databank. (Note: PLOT also implicitly produces such a data file, see the temporary files folder, under \gnuplot. Location is given with Help --> About... in the main Gekko window).

PRN: Same behaviour as for the CSV type. Note that a similar looking style of output can be accomplished with PRT (for instance prt <n> x1, x2 file=output.txt;, and PRT has many formatting options regarding decimals, etc.).

PYTHON: Exports matrices as a Python script file. For instance like this: #m1 = [1, 2; 3, 4]; #m2 = [11, 12; 13, 14]; export <python> #m1, #m2 file=matrix.py; Only matrices can be exported. For running Python more interactively, see PYTHON_RUN.

R: Exports matrices as a R script file. For instance like this: #m1 = [1, 2; 3, 4]; #m2 = [11, 12; 13, 14]; export<r> #m1, #m2 file=matrix.r; Only matrices can be exported. For running R more interactively, see R_RUN.

TSD: For interchange with AREMOS and others. With option 'CAPS=no', all .tsd variable names are written as they are (otherwise they will be written as all caps). When exporting daily frequency data, all days of the week (Monday-Sunday) are designated "active".

TSP: Gekko will write TSP records (load statements). Works for annual frequencies only.

XLS or XLSX: Gekko will try to write the data to an Excel workbook. Only frequencies matching the current frequency setting will be written. If no period is set, global time will be used. Cf. also the SHEET statement. The engine used for Excel writing can be changed with "OPTION sheet engine = ...;". You can also export a matrix to xlsx format.

ALL

(Optional). With this option, all observations are exported, regardless of the global time period. This corresponds to pre-3.0 Gekko behavior.

CAPS=

When exporting a tsd file, the default is now to write the variable names with all caps. This is because AREMOS fails if this is not done. To avoid the caps, you may use option <tsd caps=no>.

COLS

(Optional). For .csv, .prn or Excel files, this indicates whether the timeseries are running downwards in columns.

OP=

(Optional). For .gcm files, this value indicates the operator used for the SERIES statements.

DATEFORMAT=

DATETYPE=

(Optional). These options control the date format for .xlsx and .csv files, and for the use of SHEET in Gekcel. DATEFORMAT can be either 'gekko' (default, for instance 2020q3 or 2020m11) or a format string like 'yyyy-mm-dd', and the latter may contain a first or last indicator, for instance 'yyyy-mm-dd last', which indicates for quarterly, monthly or weekly data that the last day of the quarter/month/week is used. DATETYPE can be either 'text' or 'excel'. In the former case, the dates are understood as text strings (for instance '2020q3' or '2020-09-30' for a quarterly date), and in the latter case (not relevant for .csv files), the date is understood as an Excel date, which basically counts the days since January 1, 1900. This number would correspond to 44104 for the date 2020-09-31, and can be shown in Excel in different ways depending upon date format settings, language settings, etc., but the internal number itself is unambiguous. When using SHEET in Gekcel, using DATETYPE='excel' is advised for consistency. [New in 3.0.5].

variables

Variables or lists (wildcards and bank indicators may be used), and items may be separated by commas. If no variables are given, the full first-position databank is written.

TO

You may use TO to rename variables before they are written, for instance export <csv> x* to *_old file = test;, where Gekko will look for variables starting with x, and the found variables will acquire a _old suffix. This logic is similar to the COPY and RENAME statements.

 

filename

Filenames may contain an absolute path like c:\projects\gekko\bank.gbk, or a relative path \gekko\bank.gbk. Filenames containing blanks and special characters should be put inside quotes. Regarding reading of files, files in libraries can be referred to with colon (for instance lib1:bank.gbk), and "zip paths" are allowed too (for instance c:\projects\data.zip\bank.gbk). See more on filenames here.

 

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

If a variable is stated without databank, the databank is assumed to be the first-position databank.

 

 


 

Examples

 

You may export the contents of the first-position databank into a spreadsheet like this:

 

export <xlsx all> data;

 

This produces the file data.xlsx. The <all> option makes sure that all observations are exported: if omitted, only observations inside the global time period are exported. If you only want subset of the variables or a subset of the time period, you may write for instance:

 

export <2040 2050 xlsx> fy, fe, fm  FILE=sim4050;

 

This produces the file sim4050.xlsx, containing the three variables over the period 2040-50. You may also use lists or wild-card lists regarding the variables:

 

export <xlsx> fX* file=fxfile;

 

This writes all variables in the first-position databank starting with 'fX' to the file fxfile.xlsx.

 

export <2015 2020 gcm op=p> px* file=px;

 

This writes all variables in the first-position databank starting with 'pX' to the Gekko program file px.gcm. The variables are written as percentage growth SERIES statements (the data can be imported afterwards with RUN).

 

export <gdx> ats file=gamsdata;

 

This will export the array-timeseries ats to gamsdata.gdx.

 

Export of a matrix #m to Excel (matrix.xlsx):

 

export <xlsx> #m file = matrix.xlsx;

 

 

 


 

Note

 

You may use SHEET if you need to put expressions into an Excel sheet, or into particular cells.

 

If option folder = yes, and option folder bank is set, the EXPORT statement tries to write to that particular folder instead of the working folder.

 

See the Gekko menu 'Options' --> 'Program dependency tracking' or use option global dependency tracking = ...; to activate dependency tracking, so that the use of external files (for instance program files, read/written databanks etc.) are shown as a list at the end of a Gekko session.

 


 

Related options

 

OPTION folder bank = [empty];

OPTION interface csv decimalseparator = period; [period|comma]

OPTION interface csv delimiter = 'semicolon'; [semicolon|comma|tab]

OPTION interface csv ignoremissing = no; [yes|no]

OPTION interface csv ndec = 100;

OPTION interface excel ignoremissing = no; [yes|no]

OPTION interface excel language = danish; [danish|english]

OPTION interface prn decimalseparator = period; [period|comma]

OPTION interface prn ndec = 100;

OPTION interface prn delimiter = blank; [blank|semicolon|comma|tab]

 

 


 

 

Related statements

 

IMPORT, READ, WRITE, SHEET