Em 31 de outubro de 2017, Filipe escreveu:
Hi All,
I'm trying to find a way of generating variable names automatically.
I have a list of share prices: share1, share2, ...., share12. I want to
compute returns in a loop. Here is what I was doing:
# Compute returns for all shares
loop foreach i list_share
ret_$i = 100 * (log(list_share.$i) - log(list_share.$i(-1)))
endloop
The above one would return the following variables: ret_share1,
ret_share2,..., ret_share12.
My question is simple: is there a way of controlling the name of the
output variable in a different way than what is used above? I mean, how can
I get output in variables with name: ret1, ret2,..., ret12? Is there any
sequential command that can be added to ret*?
Dear Filipe,
I think you could use this:
<hansl>
loop foreach i list_share
string temp = sprintf("ret%d", i)
series @temp = 100 * (log(list_share.$i) - log(list_share.$i(-1)))
endloop
</hansl>
Um abraço,
Henrique