|
<< Click to Display Table of Contents >> COPY |
![]() ![]()
|
The statement is used to copy variables, either inside a databank, or between databanks.
Note that 'naked' wildcards are allowed in this statement, so you may for instance use a*b?c as wildcard instead of the more cumbersome {'a*b?c'}.
copy < period RESPECT FROMBANK=... TOBANK=... ERROR=... PRINT > names1 TO names2;
period |
(Optional). Local period, for instance 2010 2020, 2010q1 2020q4 or %per1 %per2+1. |
RESPECT |
(Optional). With this option, if no period is given, the global period is used. (This option can also be set as a general option with option copy respect = yes;). |
FROMBANK= |
(Optional). A databank name from where the variables are copied from. |
TOBANK= |
(Optional). A databank name to where the variables are copied to. |
ERROR= |
(Optional). With copy<error=no>, Gekko will try to copy the items, but will not fail with an error if some of the items cannot be found. |
(Optional). With this option set, Gekko will print a list of which variables are copied to where, but without actually copying anything. The option can be practical for debugging. |
|
names1 |
Variablename(s) or list(s) (wild-cards are allowed). You may prepend a databank name as bank:variable.
Indexes are allowed, like for instance x[a], x[a,b], x[*] or x[a,*]. When copying array-series elements, the destination array-series must exist beforehand. You may also use more complex wildcard names like x[a,b*c?d]. |
TO |
(Optional). If the to part is omitted, the variables will be copied to the first-position databank (with the same names), and in that case, the COPY statement is implicitly interpreted as if it included a ... to first:*, where first indicates the first-position databank. |
names2 |
(Optional). A corresponding list with the new names. You may prepend a databank name as bank:variable (or use bank:* to keep the same variable names, but put the copied variables in the databank bank). For variable names, you may use for instance a*b to use prefix a and suffix b on the names. Indexes cannot be used regarding names2 (so any indexes from names1 are transferred unchanged). |
•If no period is given inside the <...> angle brackets, no time period is used.
•If a variable is stated without databank, the databank is assumed to be the first-position databank.
•Looping: with a list like for instance #m = a, b;, you may use copy x{#m} to y{#m}; to copy xa to ya, and xb to yb.
If the RESPECT option is active, and the new name exists as a timeseries beforehand, it is only the observations inside the local time period that are copied into the existing timeseries (and not any meta-information like labels, etc.).
Inside the first-position databank
To copy items inside the first-position databank, consider the following examples:
a1 = 1; b1 = 2; c1 = 3; |
If you use the respect option, only the observations inside the global time period are used. For instance:
copy <respect> a1 to a2; |
Else:
copy <2010 2020> a1 to a2; |
will copy observations belonging to that particular period. Note that a list inside {}-curlies auto-expands if there is a name part before of after the {}, so that the example could have been done like this instead:
#m = a, b, c; //or: #m = ('a', 'b', 'c'); |
The last statement copies #m into #m2, so that #m2 also contains the strings 'a', 'b' and 'c'.
From other databanks to the first-position databank
In these cases, you typically omit the to keyword, if you are preserving the same names. You may copy variables from other databanks (either the reference databank, or databanks opened with the OPEN statement), by using a colon:
copy b:a1, b:a2; |
This will copy the two variables a1 and a2 from the databank b into the first-position databank (with the same names). For several items, using a list may be easier:
#m = a1, a2; |
where #m is a list with the timeseries names. Or alternatively, you may use the <from=...> option:
copy <frombank=b> a1, a2; //this works too: copy <frombank=b> {#m}; |
If you are copying from the Ref (reference) databank into the first-position databank, you may use this:
copy @{#m}; |
Between arbitrary databanks
In this case, the frombank= and tobank= options can be practical, for instance:
copy <frombank=b1 tobank=b2> a1 to a2; |
This copies b1:a1 to b2:a2. You may use lists instead of these names, and this will do the same thing:
copy b1:a1 to b2:a2; |
Or with lists:
copy b1:{#m1} to b2:{#m2}; |
where #m1 is the list of names to be copied, and #m2 is a list of the resulting names (that is, a renaming list). If the names are the same, you can just use ...to b2:*.
Wildcards and ranges can be used, for instance:
copy b2:a* to b1:*; |
The first statement will copy all timeseries starting with a from b2 to b1 (you could have used <frombank=... tobank=...> as well to denote the databanks. The second line does the same thing, but only regarding the name range 'a1' to 'a5'.
Copying timeseries a1 from databank b2 to the reference databank can be done with:
copy b2:a1 TO @*; //or copy b2:a1 to ref:* |
Wildcards and ranges
It is often practical to use wildcards to copy items. You may for instance copy all the items starting with fx from the open bank b1 to the first-position databank with this statement:
copy b1:fx*; |
You may copy an entire databank into the first-position databank like this:
copy b1:**; //double star matches all variable types and all frequencies |
If you for instance need to replace all the variables in the first-position databank with the variables in the Ref (reference) databank, you may use this:
clear<first>; |
Regarding syntax rules of wildcards, see more in the INDEX section. See also the wildcards page.
Array-series
You may use array indexes to pick out array-subseries to copy, cf. the following example.
open b; unlock b; clear b; //makes b editable |
If you use the frombank= or tobank= options together with explicit databank indicators (colon), the explicit databank indicators will override the frombank= or tobank= options.
If preferred, you may use copy ... as ... instead of copy ... to ....
option copy respect = no;
CLONE, DELETE, EXPORT, IMPORT, INDEX, READ, RENAME, WRITE