Variables in G7 were introduced earlier for use in add files, fadd files, do loops, and elsewhere. This section provides additional details.
The treatment of variables in G7 are similar to the treatment in DOS batch files. Up to 99 variables typically may be passed to an add or fadd file, within a do loop or function, and so on. The first argument that is passed to a file is referenced by ‘%1’, the second by ‘%2’, ..., and ‘%99’. The appearance of a percent symbol (%) within a G7 script always signifies that the following character or word should be interpreted as a variable, a keyword, or a function. In each case, when the variable, keyword, or function is encountered and evaluated, the value of the result effectively will be inserted into the script and subsequently processed by G7.
Variables
Variables in G7 were introduced earlier. All arguments are passed as text to the add file, do loop, or other routine. Variables are referenced as %1, ..., %99.
Numerical Routines
Integers often are passed to an add file or function, and integers are used as indexes for a do loop. Sometimes a calculation is needed that is based on that integer, but some adjustment is needed. The %{} operation allows such calculations. Numerical variables and constants may be referenced within the brackets, and addition, subtraction, multiplication, and division of variables and constants is permitted, and sub-calculations may be surrounded by parentheses. For example, suppose we need to print vector data to a spreadsheet. Suppose the vector elements range from 1-10, and we want to print these series in rows 6-15. We could use the “xl vecwrite” routine or we could construct a do loop like the following:
do{ xl write A %{5 + %1} vec%1 2000 2010 }(1-10)
Note that for each iteration ‘%1’, element ‘%1’ is referenced in the “vec” vector, and that series is written to row ‘5+%1’ in the spreadsheet.
Another common use of %{} is to provide unambiguous specification of variables within a script. Recall that variables ‘%1’ through ‘%99’ are legal. However, there may be ambiguity between a two-digit variable and a single-digit variable that is followed by another digit that is not part of the variable. For example, if ‘%9’ is followed by a ‘9’, it looks the same as ‘%99’ and so G7 will attempt to fill in the 99-th variable definition. To remove such ambiguity, use the following approach:
f x = %{%9}9 # Variable 9, followed by '9'
f x = %99 # Variable 99
In some cases, strings may be expanded and other text also is allowed within %{}.
Keywords
Several keywords were introduced earlier. The following is a summary of keywords in G7. Availability of particular regression statistics depends on the type of regression performed.
%date: | Insert the date. |
---|---|
%time: | Insert the time. |
%NARGS: | The number of arguments that currently are in scope. |
%%: | Treat this as text, evaluated as a single ‘%’. |
%fdate<X>: | Recover the first or last fdates setting, where X = {1,2}. |
%gdate<X>: | Recover the first, middle, or last gdates setting, where X = {1,2,3}. |
%tdate<X>: | Recover the first or last tdates setting, where X = {1,2}. |
%lim<X>: | Recover the first, middle, or last limits setting, where X = {1,2,3}. |
%title: | Recover the current graph title. |
%subtitle: | Recover the current graph subtitle. |
%vaxtitle: | Recover the current graph vertical axis title. |
%ncoef: | Recover the number of coefficients in the last regression. |
%beta<X>: | Recover the parameters from the last regression, X={1,...,ncoef}. |
%mexval<X>: | Recover the mexvals from the last regression, X={1,...,ncoef}. |
%see: | Recover the standard error of the estimate from the last regression. |
%rsq: | Recover the r-square value from the last regression. |
%rho: | Recover rho from the last regression. |
%rbarsq: | Recover the r-bar-square value from the last regression. |
%mape: | Recover the mean absolute percentage error from the last regression. |
%dw: | Recover the Durbin-Watson statistic from the last regression. |
%nobs: | Recover the number of observations in the last regression. |
%obsinregression: | |
Recover the number of observations in the last regression. | |
%logl: | Recover the log likelihood statistic from the last regression. |
%xls: | Recover spreadsheet cell contents. |
%xldate: | Recover a spreadsheet date. |
%xlgdate: | Recover a spreadsheet date in G7 date format. |
%xlyear: | Recover the year component of a spreadsheet date. |
%xlquarter: | Recover the quarter component of a spreadsheet date. |
%xlmonth: | Recover the month component of a spreadsheet date. |
%xlday: | Recover the day component of a spreadsheet date. |
%mainfontname: | Recover the typeface setting of the main G7 window. |
%mainfontsize: | Recover the type size of the main G7 window. |
%mainfontcolor: | Recover the font color of the main G7 window. |
%maincolor: | Recover the background color of the main G7 window. |
%mainfontcharset: | |
Recover the character set setting of the main G7 window. | |
%mainautofontsize: | |
Recover the auto font size setting of the main G7 window. | |
%mainfontbold: | Recover the bold font setting of the main G7 window. |
%mainfontitalic: | |
Recover the italic font setting of the main G7 window. | |
%mainfontunderline: | |
Recover the underline font setting of the main G7 window. | |
%mainfontstrikeout: | |
Recover the strikeout font setting of the main G7 window. | |
%autocomplete: | |
%edfontname: | Recover the typeface setting of the editor window. |
%edfontsize: | Recover the type size of the editor window. |
%edfontcolor: | Recover the font color of the editor window. |
%edcolor: | Recover the background color of the editor window. |
%edfontcharset: | Recover the character set setting of the editor window. |
%edfontbold: | Recover the bold font setting of the editor window. |
%edfontitalic: | Recover the italic font setting of the editor window. |
%edfontunderline: | |
Recover the underline font setting of the editor window. | |
%edfontstrikeout: | |
Recover the strikeout font setting of the editor window. |
Functions
A variety of functions also are available. The following is a summary of such functions in G7.
The following functions operate on strings. The strings either may named strings that were defined by the str command or they may be provided as text or a variable that is surrounded by quotation marks (e.g. “x1” or “%1”).