G7 Commands: F

f <variable> = <expression>
f <variable>{<date1> [- <date2>]} = <expression>
This command is one of the most commonly used as well as most powerful and useful commands in G7. It is equivalent to the LET or GENR commands in other packages, and its job is to form a variable on the left hand side from an expression on the right hand side of the equals sign. The syntax of the expressions used by f or similar to those in most programming languages. 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] (z lagged once) is invalid on the left side. A range of dates also may be provided to specify the periods to carry out the calculations.

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 puts the series in 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 fdate, and sets missing values, (-0.000001), for those observations outside the period. If “missing n” is in effect, the observations outside of the fdates period will be set to zero rather than to -0.000001.

In addition to the assignment operator (i.e. “=”), the f command can add <expression> to the left-hand series using the “+=” operator, or it can subtract <expression> from the left-hand series with the “-=” operator, or multiply with “*=”, or divide with “/=”. These operators follow the syntax for the C++ programming language, though here they operate over a range of values.

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 set to be 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.


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

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

z[3]:means z lagged three periods, i.e. z(t-3) in a common notat
s{2005.1}:means the value of s in the first quarter of 2005,
@log(w):means the natural logarithm function of the variable w.

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

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

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 topic for the differences.

Related Topics: Missing Values, Model Building, fdup, fex, frequency, id

fadd <CommandFile> <ArgumentFile> [<arg> [<arg>] ...]

The named <CommandFile> is executed first with the arguments from the first line of named <ArgumentFile>, then the <CommandFile> is executed again with the arguments from the second line of the <ArgumentFile>, and so on until the <ArgumentFile> is exhausted. Additional arguments may be supplied with the fadd command, and these will be added to each line of arguments provided in the arguments file.

For example, the <CommandFile> could be

ti %2
gr %1

and the <ArgumentFile>

gnp$    "Gross National Product"
vfnre$  "Investment in producer durable equipment"
vfnrs$  "Investment in non-residential structures"

Then the result would be three properly-titled graphs.

Related Topics: Command Files, add, addtype, punch, title

fdates [date1 [date2]]
fdates off
fdates ±n1 ±n2
This command sets or resets the dates in effect for subsequent f commands and other operations. For a series that exists in the workspace or in the assigned bank, values may be modified within that period without affecting the existing values outside of the period.


fdates 1980.1 2010.4

In this case, subsequent f commands only alter the value of a series between the first quarter of 1980 through the last quarter of 2010.

The default fdates implicitly are defined in G.CFG: <fdate1> is the first period of the “Default base year of workspace file” as defined in G.CFG, and <fdate2> is the period implied by “Default maximum number of observations per series in workspace” in G.CFG.

“fdates off” resets the fdates to the default.

If valid dates have been specified, then they can be adjusted, moving either or both dates either forward or backward in time.


fdates +0 -2

If the command above follows the command in the first example, then the adjusted fdates will specify the period quarter one of 1980 through quarter 2 of 2010.

Related Topics: Dates in G7, G.CFG file, coef, f, flow, gdates, index, punch5

fdup <variable> = <expression>

In the context of the G7 program, the fdup command is equivalent to the f command. However, when passed to the Build program through a .SAV file, it does nothing. It’s main purpose is to do a calculation in one .REG file that already was done in another .REG file for use in the same a model, and so the equation does not need to be repeated. (“dup” stands for “duplicate”).

Related Topics: Model Building, f, fex, id

fex <variable> = <expression>

The fex command is just like the f command in the context of G7. However, when passed to the Build program in a .SAV file, it only computes the left-left side variable and puts it into the workspace. It does not put the right-side variables of the expression into the workspace and does not put code for this calculation into the model. It often is used to define historical values of EXogenous variables, such as tax rates, and historical values of dependent variables of behavioral equations.

Related Topics: Model Building, f, fdup, id

findmode < m | a>

When multiple databanks have been assigned, this command sets the mode for searching through banks when looking for a time series. There are two modes: manual (m) and automatic (a). Manual is the default. In this mode, G7 searches first the workspace bank, and then the bank in position ‘a’. If you want to access or type a series in any of the other banks, you explicitly must specify the desired bank before giving the series name. For example, if listbanks shows that you have four banks assigned in positions ‘a’, ‘c’, ‘e’ and ‘f’, and you want to type the series gnp in bank f, then you must type:

ty f.gnp

In automatic mode, G7 automatically will search through the workspace bank and then the assigned banks in alphabetical order until it finds a series with the specified name. If the name is a common one, such as “gnp”, then be warned that you might not get the series from the bank you expected! In other words, if there was a monthly series in bank ‘c’ named “gnp” and a quarterly series in bank ‘f’, then typing

ty gnp

would get the monthly version.

Related Topics: Assigned Banks, id, listbanks, type

flow <matrix> <vec> [year]

Multiply each column of the matrix by the corresponding element of the named vector. If no year is named, the command works over the fdates range. This command is the opposite of coef command.

Related Topics: coef, fdates, getsum, move, ras, rowscale, scale

format {<width> <decs> <obsPerLine>} | “off”

This command is used to override the default settings of the type and stype commands for the width of the data, the number of decimal points, and the number of observations printed on each line. The <width> and <decs> arguments also apply to the matty or matpr command. If you give the “format off” command, this returns G7 to its default style of formatting.

If the command was not issued earlier, G7 will determine the format to use based on the absolute value of selected elements of the series. This sometimes will result in a messy .SAV file if data are printed at different widths and decimal points.

Related Topics: matty, save, stype, type, print

(freq)uency <series name> [frequency()<1|2|4|12>]

Some of the most Frequently Asked Questions about G7 involve the topic of series frequencies.

Each time series in a G data bank has associated with it a one byte integer representing the frequency of the series. This frequency is set at the time of the creation of the series, but it may be changed with the freq command. In a data statement, G7 determines the frequency of the series by looking at the dates. An annual date (1995, 1995.0) will indicate that the series is annual. Quarterly dates (1991.3) and monthly dates (1994.005) work accordingly.

Certain functions in G7 will change the frequency of data, for example by performing conversions from quarterly to annual and back, or from monthly to quarterly. These functions, of course, create the new series in the target frequency.

A formula or expression calculated with the f command must involve series that all possess the same frequency (or else no frequency), and the resulting series will have that same frequency. However, note that the f command can be used to set a series to a constant, or to a linear time trend, using the @cum() function. In these cases, the frequency is 0, or undefined. As just mentioned, G7 is quite happy to use series created in this way in expressions with other series. However, the Compare program will complain if it is asked to print a series with no frequency. To ensure that such series are assigned a frequency, use the freq command, or use the dfreq command in the beginning of your session or add file.

The freq command displays a series’ frequency and allows you to change it. The series and its new frequency will be put into the workspace bank. Note that this is true even if the series originally was in an assigned bank.

Related Topics: Compare, Dates in G7, G7 Functions, data, dfreq, f

function <function name> { <function body> }
function clear [<name>]
The function command enables users to define a function that will be available for the rest of the G7 session. Arguments may be passed to the function, in which case they are referenced in the same way as in add files, with “%1”, “%2”, etc. The following example is a function that just states its arguments and how many arguments have been given. function clear will remove all defined functions, or if a function name is specified, then that function will be removed.

Example 1:

function TEST {
   if(%NARGS == 0){      ic Zero arguments were passed to the function TEST.        }
   else if(%NARGS == 1){ ic The argument %1 was passed to the function TEST.        }
   else{                 ic At least two arguments, %1 and %2, were passed to TEST. }

The second example demonstrates several tests, first for the comparison of strings and then for the comparison of numbers. The arguments may be replaced by the standard G7 variables (i.e. %1, %2, etc.) defined for “add” files and loop iterators.

Example 2:

if( Clopper != Almon ){
   ic String inequality test failed.
   ic Clopper is not the same as Almon.
if( A <= C ){
   ic Character less than or equal to comparisons.
if( -1 < -0.5 ){
   ic Integer evaluation with negatives.
if( ( 2 < 3 && 3 <= 4 ) || A <= C ){
   ic Multiple evaluations with AND, OR, and parentheses.

Recursive techniques may be employed.

Related Topics: Command Files, add, do

fvread <vector_name> <year> <skip>

The fv in this command name stands for “folded vector.” The vector recorded in this format is “folded” across several lines. Each line can begin with several columns of comment, and <skip> argument is the number of columns to skip at the beginning of each line. After the comment follows the elements of the vector, divided across several lines. There must be present as many elements as are in the vector, and they must be in order.


fvread fd 1997 10
finaldem 1   23 36 83 92 32
finaldem 6    8 23 73 80 75

This example will put the vector (23, 36, 83, 92, 32, 8, 23, 73, 80, 75) into the fd vector of the default Vam file for the year 1997.

Previous topic

G7 Commands: E

Next topic

G7 Commands: G

This Page