|
<< Click to Display Table of Contents >> EXPORT |
![]() ![]()
|
The statement writes (supported) variables to a non-gbk databank file, for instance export <csv>, export <xlsx>, etc. Beware that there are differences between the close cousins EXPORT and WRITE regarding time periods used. There is the following equivalences: export = write<respect> and the inverse: write = export<all>. If a local <> period is set, WRITE and EXPORT behave in the same way.
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". |
export < period format ALL CAPS=... COLS DATEFORMAT=... DATETYPE=... OP=... BANKNAME=... > filename ;
export < period format ALL CAPS=... COLS DATEFORMAT=... DATETYPE=... OP=... BANKNAME=... > 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, parquet, prn, python, r, tsd, tsp, xls/xlsx (regarding gbk, see the WRITE statement). •arrow: The Apache Arrow format, importing is not supported. Instead, consider using the similar parquet format with many more features, including import. See the examples under R_RUN or PYTHON_RUN. •csv: Only frequencies matching the current frequency setting will be written. Array-series are supported and will be represented by names like x[a,b]. •flat: This is a special Gekko text-based format with lines that resemble series statements. See more details in the IMPORT section. Array-series are supported and will be represented by names like x[a,b]. •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. Array-series are supported. See also the .flat format for a faster version of this format. Use option interface gcm ndec (default: 6) to set the max number of decimals (operator *= has 2 decimals added on top of that option value). If ndec is set to 20 or more, the numbers are written in raw representation. •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. Array-series are supported and will be represented by names like x[a,b]. (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). Array-series are supported and will be represented by comments like # x[a,b]. •parquet: A binary dataframe representation using Apache Parquet, details in this appendix. Note that only (array-)timeseries (see SERIES) are stored. Think of parquet as "better and faster" than .csv. The parquet format supports import, too, and a roundtrip (exporting and importing data via a parquet file) will preserve all data and metadata, except data-traces. The format is very convenient for using together with for example Python, R, SQL, etc. •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.). Array-series are supported and will be represented by names like x[a,b]. •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". Array-series are not supported. •tsp: Gekko will write TSP records (load statements). Works for annual frequencies only. Array-series are not supported. •xls/xlsx: Gekko will write the data to an Excel workbook. Only frequencies matching the current frequency setting will be written. Array-series are supported and will be represented by names like x[a,b]. 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 (like WRITE). |
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 .xlsx 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. |
BANKNAME= |
(Optional). For the .parquet format, sets the name used in the id and bank columns (when this option is omitted, the .parquet filename without extension is used). An empty string will be ignored. |
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.
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> x1, x2, x2 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. Only observations in the global time period are exported.
Export of a matrix #m to Excel (matrix.xlsx):
export <xlsx> #m file = matrix.xlsx; |
You may use the <gcm> format to fetch a "series statement" for some timeseries x:
time 2025 2028; |
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.
option folder bank = '';
option folder bank1 = '';
option folder bank2 = '';
option interface csv decimalseparator = period;
option interface csv delimiter = semicolon;
option interface csv ignoremissing = no;
option interface csv ndec = 100;
option interface excel ignoremissing = no;
option interface excel language = danish;
option interface excel modernlook = yes;
option interface gcm ndec = 6;
option interface prn decimalseparator = period;
option interface prn delimiter = blank;
option interface prn ndec = 100;