Page 1 of 1
Forced a loop
Posted: Sun Jul 31, 2011 10:26 pm
by Aktar
Hi,
Is there a possibility to forced a loop even if we have a error message?
In fact i created a loop to test different lag specifications for MS-TVTP model. And for each lag i compute a Ljung-box test for my residuals (the test is inside the loop). The problem is that for some specification, the LB test doesn't run (because of problem of concvergence, my series of residuals display for each date "NA"...it is not the problem) and the loop stop.
I have this message:
Code: Select all
Ljung-box statistics - order 1
The Error Occurred At Location 267, Line 21 of LB
Called From Location 3742, Line 265 of loop/block
## REG7. Variance is Zero
## REG7. Variance is Zero
The Error Occurred At Location 267, Line 21 of LB
Called From Location 3742, Line 265 of loop/block
After this messgae the loop stop. Is there a possibility to continue the computation? Thanks
Regards
Re: Forced a loop
Posted: Mon Aug 01, 2011 9:01 am
by TomDoan
Aktar wrote:Hi,
Is there a possibility to forced a loop even if we have a error message?
In fact i created a loop to test different lag specifications for MS-TVTP model. And for each lag i compute a Ljung-box test for my residuals (the test is inside the loop). The problem is that for some specification, the LB test doesn't run (because of problem of concvergence, my series of residuals display for each date "NA"...it is not the problem) and the loop stop.
Use ENV TRAPERRORS before the loop. You can turn standard error handling back on with ENV NOTRAPERRORS
Re: Forced a loop
Posted: Mon Aug 01, 2011 9:34 pm
by Aktar
Thank you.
Precedently i had:
Code: Select all
The Error Occurred At Location 267, Line 21 of LB
Called From Location 3742, Line 265 of loop/block
## REG7. Variance is Zero
## REG7. Variance is Zero
The Error Occurred At Location 267, Line 21 of LB
Called From Location 3742, Line 265 of loop/block
But It seems that this code is not appropriate. The prog display this error message.
Code: Select all
The Error Occurred At Location 267, Line 21 of LB
Called From Location 3800, Line 267 of loop/block
And the loop stop. I used this instruction before the loop.
I don't understand, because when i have this error message...
Code: Select all
The Error Occurred At Location 233, Line 13 of MARKOVINIT
Called From Location 867, Line 43 of loop/block
... the loop continue to work (markovinit is a function of my MS-TVTP model), and for a simple LB test the loop stop.
Maybe i can creat a command which execute @lb test only under certain conditions like:
if the first data of my serie reso (which used from Ljung-box test) is different from NA, execute @lb otherwise continue the loop.
It is possible?
Thank you
Re: Forced a loop
Posted: Tue Aug 02, 2011 9:21 am
by moderator
I'm not sure that ENV TRAPERRORS actually allows RATS to continue even if it encounters an error--I think it may just suppress the error. I can check on that, but in the meantime:
1) If the behavior is different depending on the location, it's probably because one condition is just a warning, while the other is an error. You'd have to let it display the error messages to know for sure.
2) As you suggest, your best option is usually to test for the appropriate condition and then only execute the relevant code conditional on passing that test. So, if you do indeed have a known condition you can test for, use that approach. Note that you do not need/want a matching "END" for your "IF" instruction when the IF occurs inside a loop or other compiled section.
Regards,
Tom Maycock
Re: Forced a loop
Posted: Wed Aug 03, 2011 12:24 am
by Aktar
My condition should be:
if the first value of my serie p1tr is different from NA, lb is executed.
I tried this
Code: Select all
if.not.p1tr(1976:2)=NA
@lb(lags=1) reso
but it doesn't work. Surely because NA is a real.
An d i tried
Code: Select all
@lb(lags1) reso=%if(%valid(p1trr))
but it doesn't work too.
Thanks for your help.
Re: Forced a loop
Posted: Wed Aug 03, 2011 1:53 am
by jonasdovern
I think you can use something like
Code: Select all
if %valid(p1tr(1976:2)) {
@lb(lags=1) reso
}
Re: Forced a loop
Posted: Wed Aug 03, 2011 2:46 am
by Aktar
As for precedent solution, it doesn't work. Thank you, what is strange is that i have no error message or something else... the prog stop after the last command before the code in question.
Re: Forced a loop
Posted: Wed Aug 03, 2011 9:10 am
by moderator
First, note there are several issues with this syntax:
if.not.p1tr(1976:2)=NA
First, as Jonas noted, you should use the %VALID() function instead. Also, the = sign is the assignment operator, not the is equal to operator, so this would assign a value, not test it. Use double equal signs (==) to test for equality. Finally, the reserved variable representing the missing value code is %NA, not NA.
Again, though, Jonas' suggestion of using %VALID() is correct. If the program isn't functioning properly with that change, you need to check the rest of your logic. You can insert DISPLAY or MESSAGEBOX instructions at various points in the code to verify which sections are, or are not, being executed. If "nothing" seems to happen, check to make sure that your loop(s) are closed properly with END instructions. If you used { to start a statement block after the IF, make sure that is being closed properly.
Regards,
Tom Maycock
Estima