SET x / = function(T)

Helpful hints, useful features you may not be aware of, and more
TomDoan
Posts: 7728
Joined: Wed Nov 01, 2006 4:36 pm

SET x / = function(T)

Unread post by TomDoan »

We frequently see programs with SET instructions looking like:

Code: Select all

SET Q / = %seesq**0.5
SET H / = EXP(RANGE - 0.43)
SET U / = 0.0
It's probably been at least 15 years since you needed the / in this situation, but some people have gotten programs second and third hand from long-time RATS users. SET is going to take one of four basic forms, depending upon what control you need over the range:

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

The first of those controls both the start and end entries. The second begins from the default "start" (usually entry 1) and goes to the entry given by end. The third begins at entry start and runs until the default "end" (usually the end of the workspace), and the last runs over the whole range (generally 1 to the end of the workspace). The "/" in the old style of code shown above chooses the default range for both limits (it's the equivalent of * *). But that's assumed anyway, so it isn't necessary.

In most cases, you can just use that last, simplest form. If the function can't be evaluated at all entries (due to lags, for instance), the output series will just have missing values for those entries that must be skipped. Some control of the range is needed in a few situations:

1. You're creating the series in two (or more) separate ranges.
For instance:

Code: Select all

set y 1 2 = 0.0
set y 3 100 = 2*y{1}-y{2}+u+.3*u{1}
If instead you do

Code: Select all

set y = 0.0
set y = 2*y{1}-y{2}+u+.3*u{1}
the first SET will zero out the whole series (which is OK), but the second will try to compute y(1), find that it needs y(0) and y(-1), and gets NA as the result. It then computes y(2), again getting NA. Then in computing y(3), it will need y(1) and y(2) which are now NA's, so it gets NA, etc; thus filling an entire series of NA.

2. You have series defined over a completely different range from the main workspace.
A common situation is where you have series of simulations. Any SET instructions operating on a series running over the number of simulations will likely need the explicit range:

Code: Select all

set workwt 1 ndraws = weights(t)
3. You have complicated function which uses series of matrices which aren't defined over the full range.
This commonly occurs with DLM, which defines most of its output series in the form of SERIES[VECTOR]. In this example, xstates is a SERIES[VECT] which is only defined over the estimation range (dstart to dend).

Code: Select all

set nairu dstart dend = xstates(t)(5)
Post Reply