Forming Variables

Most transformations of existing variables into new variables are done with the f command. Such transformations alter the values of a variable over a period specified by an fdates command. The default fdates are determined by the maximum number of observations that are defined in the G.CFG file.

The general form of an f command is

f <variable> = <expression>

The resulting variable is placed in the workspace bank. If the left-hand variable already is in the workspace bank, then its values may be modified with the “+=”, “-=”, “*=”, or “/=” operators. By using these operators, the right-hand side expression will be added or subtracted from the left-hand side, or the left-hand side will be multiplied by the right-hand side values, or the left-hand side values will be divided by right-hand side values. These operators follow the syntax for the C++ programming language, though here they operate over a range of values. To add the results of an expression to a variable, where the variable already exists in the workspace bank, the syntax is

f <variable> += <expression>

Example:

f x{1980.1-2010.4} = y*(z[3] + v*@log(w))/s{2010.1}

Variable x is calculated and placed in the workspace using the variables ‘y’, ‘z’, ‘v’, ‘w’, and ‘s’. These variables must exist already. Note in the example:

  • x{1980.1-2010.4} Calculate the right-hand side values from the first quarter of 1980 to the fourth quarter of 2010 and copy the values into series x..

  • z[3] means z lagged three periods, i.e. z(t-3) in a common notation.

  • s{2010.1} means the value of s in the first quarter of 2010.

  • @log(w) means the natural logarithm function of the variable w.

The full list of @ functions are shown in the list of functions.

Rules for f statements

Any algebraically legal expression is allowed, including nested parentheses.

The left side variable must be a single variable, or a variable with a subscript to indicate a specific time. For example, z and z{2010.1} are valid variables on the left side. However, z[1] is invalid on the left side.

For a series that exists in the workspace or in the assigned bank, the f command modifies the value within the period specified by fdates without affecting the existing values outside of that period, and it puts the series into the workspace. Otherwise, the f command creates a series, determines the values using the expression on the right-hand side of the f command for the period specified by fdates, and sets missing values, (-0.000001), for those observations outside of the period. If missing n is in effect, the observations outside of the fdates period will be set to zero instead of -0.000001.

For example, if we have in effect the following fdates command:

fdates 1978 2010

then for an f command

f x = (expression)

if ‘x’ is an existing series either in the workspace or the assigned bank, ‘x’ will be placed into the workspace with values from 1978 through 2010 being taken from the expression. Otherwise, ‘x’ is created with values taken from the expression from 1978 through 2010, and taken as missing for the rest of the period.

Variable names must begin with a letter and may contain up to 32 letters, digits, or the ‘$’ or ‘_’characters. Do not use a digit as the first character.

Powers are obtained using the @sq and @pow functions, not ** or ^.

Division by zero in an f command is legal and yields zero as a result.

Right-hand-side expressions too long to fit on a single line may be continued by using a +, -, *, or / as the last character on a line.

The commands f, fex, and fdup have exactly the same effect in G7 but very different effects in Build. See the Model Building for the differences.

Other Commands for Transforming Variables

(miss)ing <y|n>

This is ‘y’ by default. If it is set to ‘n’, then all values that are missing in the databank will be set to zeroes. Otherwise, they will remain as missing values (i.e. -0.000001).

ls [-<flag>] <x> <y> <date1> [<date2>] [direction]

This linkseries command takes series x and y from the workspace or the assigned bank and calculates their ratio at the specified linking date <date1>. This ratio then is used to move ‘x’ with non-zero entries from series ‘y’. The linking direction can be ‘f’ for forward or ‘b’ for backward. The default is ‘f’. If the variable x is found in the workspace, then the result is stored with name x in the workspace. If a bank letter is provided for x, and if this bank is the default Vam file, then the modified value of x is stored in the Vam file. Otherwise, the result is stored to the workspace. If the optional date <date2> is provided, then linking will extend from the base period <date1> to the terminal period <date2>.

If the signs of the values in x and y are not the same, then the result will move in the opposite direction of the guide series; this usually is not desirable and a warning will be given. Three alternatives to the basic routine may be implemented by specifying a flag.

-f: force the calculation using standard algorithm without reporting problems. -i: if x and y are of opposite sign in the base year, then ensure positive correlation between x and y such that

x = a + b*y b = x{date} / y{date} * sign( x{date}*y{date} ) a = x{date} - b * y{date}

-a: if x and y are of opposite sign in the base year and the problem is ill-conditioned such that y lies close to zero in the link year, then ensure positive correlation between x and y such that

x = a + b*y b = x{date}/ AVG(y) * sign( x{date}*AVG(y) ) a = x{date} - b * y{date}

where AVG(y) is calculated from fdate1 to <date>, if direction is ‘b’, or from <date> to fdate2, if direction is ‘f’. This may be useful when y{date} is close to zero so that scaling parameter b is large, thus scaling x excessively. If AVG(y) is close to zero, then b = x{date} * sign( x{date}*AVG(y) ). It is the user’s responsibility to ensure that the results are useful.

ctrl <x> <concept> <group>

Imposes the values of <x> series as a control total on a <group> of sectors of a given <concept> (such as exports). If the variables to be controlled are found in the workspace, then the results will be stored in workspace with names formed by <concept> and given sectors. If a bank letter is provided for <concept>, and if this bank is the default Vam file, then the modified values will be stored in the default Vam file. Otherwise, the results will be stored to the workspace.

For example, the command:

ctrl tot out 1-10 (4-7) 13 15

imposes the values of tot as a control total on the named sectors out, i.e. sectors 1 to 10, except for 4 through 7, and then 13 and 15.