On Wed, 5 Aug 2015, Wingenroth, Thorsten wrote:
I tried the following script:
set echo off
set messages off
# sample function call
nulldata 1800
setobs 5 2008-01-01 # a daily dataset should be already in place
loop foreach a RHT TKA
string ausgabe = "Aktie " ~ "$a"
print ausgabe
series "$a"
$a = yahoo_price($a)
endloop
As you might guess, the idea is to download a couple of time series
from yahoo. Each series should receive the name of the stock.
However, apart from the fact that it is not working (I am happy to
get help here, too), I get the following error message:
> set messages off
>> # sample function call
> nulldata 1800
Sorry, this command is not available in loop mode
Error executing script: halting
> nulldata 1800
But I am not in loop mode! And the command "nulldate" is not in the loop!
To me, it seems that the loop is not finished when an error is raised.
When you want to replicate the error, you might need to comment out
$a = yahoo_price($a), run it and then remove the # and run again.
Then again, comment out, run, remove the comment, run. The
respective error message appears only every second run.
Thanks for the report, but so far I'm not able to replicate this with
CVS gretl (on Linux). The errors in your script are (1) that when
declaring a series you need to provide an unquoted name (that is, an
identifier, not a string literal), and (2) it's the inverse problem
with the argument to yahoo_price: it should be a string. Corrected
version:
loop foreach a RHT TKA
string ausgabe = "Aktie " ~ "$a"
print ausgabe
series $a = yahoo_price("$a")
endloop
From that I get:
<output>
Aktie RHT
RHT imported ok
Aktie TKA
Ticker TKA not found
</output>
Now, as regards the loop hang-up you describe, I can't provoke it: no
matter how many times I comment out and uncomment the yahoo_price line
in the original version, running the script always gives me
<output>
Aktie RHT
Unexpected symbol '"'
Invalid declaration
> series "$a"
</output>
which is a correct error message regarding the bad series declaration.
Maybe there's something I'm missing in exactly how the script is being
run?
Allin Cottrell