RATS 10.1
RATS 10.1

SET( options )  series start end = function(T)

SET is the general data transformation instruction. By using arithmetic operators and functions, you can create almost any transformation. RATS also has a number of special purpose instructions such as SEASONAL for creating seasonal dummies and FILTER and DIFFERENCE for difference transformations. SET operates on complete data series. Use COMPUTE for calculations with scalars or matrices.

Wizard

You can use the Data/Graphics—Transformations Wizard to do general transformations. Select the “General-Input Formula” action.

Parameters

series

The series to create or set with this instruction.

start, end

(Optional) The range of entries to set. If you have not used a SMPL instruction, this defaults to the standard workspace, regardless of the series involved. However, in effect, RATS cuts this back to the maximum range available given the transformation by setting to “missing” all entries which it cannot compute.

function(T)

This is the function of the entry number T which gives the value of entry T of series. There should be at least one blank on each side of the =. The function can actually include multiple expressions, separated by commas. The series will be set to the values returned by the final expression in the list.

Options

FIRST=real expression/FRML for first entry set [unused]

Use FIRST when the first entry of series requires a different formula than the remaining entries; for instance, a benchmark value. The option will accept a FRML (formula) so it can adapt to the value of start.

 

STARTUP=expression/FRML evaluated at period "start"

You can use the START option to provide an expression which is computed just once, before the regular formula is computed. This allows you to do any time-consuming calculations that don’t depend upon time. It can be an expression of any type.

 

SMPL=Standard SMPL option [unused]

You can supply a series or a formula that can be evaluated across entry numbers. Only entries for which the SMPL series or formula are non-zero will be set.

 

[PANEL]/NOPANEL

When working with panel data, NOPANEL disables the special panel data treatment of expressions which cross individual boundaries.

 

SCRATCH/[NOSCRATCH]

Use SCRATCH when redefining an existing series (that is, when series appears in the function) and the transformation uses data from more than just the current time period T of series. You don’t need it if only one of these is true.

Description

This sets the values of entries start to end of series by evaluating the function at each entry T, substituting for T the number of the entry being set. You can omit the T subscript in most cases—see the note below.

The Variable T

When you do a SET instruction, the variable T is always equal to the number of the entry being computed. You can use this to create trend variables and time period dummies:

 

set trendsq = t^2                ;* Creates “time” squared.

set postwar = t>=1946:1        ;* Creates a postwar dummy for 1946 on.

Series References and Lag Notation

You can refer to the current entry of a series by just using the series name. A lag of a series can be written series{lag}. Leads are negative lags—so GDP{1} is GDP in the previous period and GDP{-1} is the next period. Note that, compared to some other software, RATS uses {} rather than () and uses {1} for the lag rather than (-1).

 

If you are referencing a series indirectly, using numbers or a loop index, use index{0} to get the current entry. The {0} makes it clear that you are referring to a series, not an integer.

Missing Values

SET propagates missing values through the formula. With only two exceptions (the %VALID(x) function and the %IF(x,y,z) function), any operation which involves a missing value returns a missing value.

 

SET also sets to missing any observation which involves an illegal operation, such as divide by zero and square root of a negative number.

Unnecessary / for Date Range

If you look at a program written for (much) older versions of rats, you may see a SET instruction that looks like


set gnp / = log(gnp)


The added / (for default range) is harmless but unnecessary—if there aren’t start and end parameters, SET uses the default range.

Examples

set gnp = log(gnp)


replaces the series GNP by its log.


 

set xswitch 1951:1 1998:4 = %if(x>=0.0,xpos,xneg)


makes XSWITCH equal to either the current entry of XPOS or of XNEG, depending upon whether X is positive or not:


 

set(first=0.0) rw = rw{1}+%ran(1.0)

 

makes RW a "random walk" with an initial value of 0 at entry 1, adding N(0,1) increments. Without the FIRST option, this would create a series of missing values since RW{1} isn't defined when T=1.


 

set u = %ran(1.0)

set(first=0.0) x = u+.5*u{1}


generates U as a series of random numbers, then makes X as a moving average of U. Again, without the FIRST option, the series would be all missing values. (Note, by the way, that you should discard the first few entries of a series generated this way since 0.0 is a convenient starting point but isn't representative of the stationary MA(1) process).


 

set lag1 = %if(%period(t)==1,0.0,x{1})

set lag2 = %if(%period(t)<=2,0.0,x{2})

set lag3 = %if(%period(t)<=3,0.0,x{3})

 

This is for panel data. These generate three series called LAG1, LAG2 and LAG3 which are lags of X, padded with 0's for the entries at the start of the individual's record for which there is no data. X{1} by itself is a missing value for the first period in an individual's record.

 


Copyright © 2025 Thomas A. Doan