RATS 10.1
RATS 10.1

Instructions /

OPTION Instruction

Home Page

← Previous Next →

OPTION  SWITCH   optionname   default

 

or

 

OPTION  CHOICE   optionname   default number    list of choices

 

or

 

OPTION  datatype optionname   default value

 

Use OPTION to define options for a PROCEDURE. When you execute the procedure, these options are very similar to options for standard RATS instructions. All OPTION statements should be near the beginning of the procedure.

Parameters

optionname

This is the name which you are assigning to the option. Within the procedure, you must use its full name. However, when you execute the procedure, only the first three characters are significant, so make sure you don’t use conflicting names (RATS will warn if you do so). Also, do not use a name which begins with the letters NO.

 

The option names are local to the procedure, so you are free to use the same option names in other procedures.
 

By default, all options are passed by value. SWITCH and CHOICE options are always passed by value. You cannot change the value of such an option within the PROCEDURE.

 

If you want an option to return a value, you need to pass it by address. To do this, use *option name rather than option name alone.

default (for SWITCH)

Use the value 0 if you want the option “off” by default, or the value 1 if you want it to be “on”. If you don’t specify a value, this defaults to 0 (off).

default number (for CHOICE)

the listed choice (by position in the list of choices, not by name) you want to be the default. Use a 0 if you want the default to be “not selected.”

list of choices (for CHOICE)

the keywords (separated by blanks) that you want to represent the choices. Only the first three letters are significant. If you are using a PROCEDURE option to pass a choice for a standard RATS instruction, you should list the choices in exactly the order used in the description of the instruction.

datatype

For value options, this can be any of the RATS supported data types.

default value

(for value options). Omit this if you want the default for the option to be “not selected.” You can use global variables or procedure parameters in a default value expression. However, all such variables must have been introduced before the OPTION instruction. You cannot use local variables.

 

Subject to these restrictions, default value can be

for any option passed by address: a single variable or array element of the proper type.

for REAL, INTEGER, COMPLEX, LABEL or STRING: any expression of the proper type.

for SERIES or EQUATIONS: a series or equation name, or an integer expression (for the "handle")

for arrays, FRMLS, MODELS and PARMSETS: a single variable (global variable or parameter) of the proper type.

for FUNCTIONS, a FUNCTION which has the identical return type and parameter list.

 

Coding Within the Procedure

You can use the option names as local variables of the indicated type within the procedure. However, if an option is passed by value, you cannot set it within the procedure. If you need to do something like that (if, for instance, a SWITCH has to be ON if some other option is used), set a local variable equal to the option, and change the local variable.

SWITCH options are INTEGER with 0 or 1 values

CHOICE variables are INTEGER with values 1,2,...; or 0 if there is no default and the option isn’t used on the EXECUTE. Note that the value of a CHOICE variable is not equal to the keyword for the choice; it is equal to the position in the list of choices.

Passing Through to RATS Instructions

A procedure option can be used to pass choices to the options on the standard RATS instructions by using

      

instruction option name=optionname ; for instance, PRINT=PRINTOUT

 

This works even for SWITCH and CHOICE options. For instance,

 

procedure doreg depvar

type series depvar

option  switch  printout  1

 ...

linreg(print=printout, ...)

 

The PRINT option on LINREG will be “off” if you use NOPRINTOUT on the EXECUTE and “on” otherwise.

The %CHOICE Function

If you are trying to pass information to a choice option on a RATS instruction, you can also use the function %CHOICE(choicelabel). For instance,

 

compute fchoice=%if(spencer,"spencer","henderson")

filter(type=%choice(fchoice)) ...

 

will pick TYPE=SPENCER if the SPENCER variable is "true" and TYPE=HENDERSON if not.

The %DEFINED Function

You can use the function %DEFINED(option or parameter name) to determine whether or not an option or parameter was given a value when the procedure was executed. It returns 1 if it was defined and 0 otherwise. If an option has a default value, it will always be “defined”, since it will, at minimum, get the default value. We use %DEFINED extensively in our procedures to ensure that the user executed the procedure in the proper form. See the final example below.

Examples

option  choice  type 1  flat tent

 

The TYPE option has choices FLAT and TENT with FLAT (choice 1) the default.


 

option  real variance 1.0

option  symm vmatrix

 

Option VARIANCE is REAL with a default of 1.0; option VMATRIX is SYMMETRIC with default of “not selected”.


 

The code below is taken from the @TSAYTEST procedure, which does an arranged regression test for threshold autoregression.

 

This procedure requires that the user supply a series of threshold values using the THRESHOLD option. The code below checks to make sure that a series has been supplied for this option, as well as for the dependent variable parameter. If the user has failed to supply either item, the procedure generates a message detailing the required syntax, and then exits from the procedure.

 

if .not.%defined(threshold).or..not.%defined(depvar)

{

 display $

  "Syntax: @tsaytest(threshold=threshold series) depvar start end"

 display "        # list of regressors"

 return

}


 


Copyright © 2025 Thomas A. Doan