UNTIL Instruction |
UNTIL condition
statement or block of statements executed until condition is “true”
END UNTIL (omit if UNTIL block is nested inside another compiled section)
UNTIL initiates a conditional loop of instructions. RATS will execute the instructions in the loop (the statement block) repeatedly until a specified condition is true. Because UNTIL tests the condition at the end of the loop, RATS will always execute the statements in the loop at least once. WHILE is similar but tests before it starts.
Parameters
|
condition |
This is the expression that UNTIL tests. It can either be an integer or a real-valued expression. The condition is true if it has a non-zero value (such as 1) and false if it has value zero. Usually you construct it using logical and relational operators. |
Statement Block
The statement block can be a single instruction, or a group of instructions enclosed in braces. It can also be a DO, DOFOR, WHILE, UNTIL or LOOP loop, or an IF-ELSE block. If you have any doubt about whether you have set up a block properly, just enclose the statements that you want executed in { and }.
If the UNTIL instruction is the first instruction in a compiled section, you must enclose the loop in an extra set of { and } to signal the limits of the compiled section.
Comments
Usually, the condition compares two variables, and it is quite common for one of these to be set only within the statement block following UNTIL. Since the condition is processed first (though not executed first), RATS will not yet have seen this variable. To get around this, you must DECLARE any variable which is introduced later in the loop.
Example
set smpl = 1.0
compute lastnobs=-1
{
until lastnobs==%nobs {
linreg(smpl=smpl) depvar
# constant testv1 testv2 testv3 testv4
set normalize = abs(%resids/sqrt(%seesq))
set smpl = smpl.and.(normalize<3.00)
}
}
This keeps running a regression, each time dropping all observations with residuals larger than three standard errors until no more observations are dropped.
Copyright © 2025 Thomas A. Doan