Page 1 of 1

TRansforming a series of Reals into a series of integers

Posted: Tue Nov 15, 2016 2:02 am
by Jules89
Hey Tom,

I created some series of reals which I wanted to use in a dofor loop. Within this loop I would like to take the first element of the series[REAL] and transform that number into an integer, such that I can use it for lags.
This code works fine:

Code: Select all


declare SERIES[Real] onem
declare SERIES[Real] threem
declare SERIES[Real] sixm
declare SERIES[Real] twelvem


set onem = 22
set threem = 66
set sixm = 132
set twelvem = 264

display onem(1)
declare series[integer] lag
gset lag = fix(onem)
compute lag1 = lag(1)
display lag1

The output is

Code: Select all

22.00000
22
But when I do the same thing in a dofor-loop the outcome is strange:

Code: Select all

dofor z = onem threem sixm twelvem

   declare series[integer] lag
   gset lag = fix(z)
   compute lag1 = lag(1)
   display lag1

end do
Outcome:

Code: Select all


Outcome:

1
2
3
4

Instead of 

22
66
132
264

Re: TRansforming a series of Reals into a series of integers

Posted: Tue Nov 15, 2016 7:31 am
by TomDoan
You want

gset lag = fix(z{0})

z by itself (in this context) is just the "handle" to the series.

Re: TRansforming a series of Reals into a series of integers

Posted: Tue Nov 15, 2016 1:49 pm
by Jules89
Thank you very much Tom.
I used your advide and it worked. But I do not really understand what is going on. Why exactly does fix(z) within my loop not work?
As far as I understand what a loop is dooing, z should be replaced by onem in the first iteration, by threem in the second and so on and so on.
What is fix(z{0}) doing and why is there a zero in the curly brackets? What would happen if I put a 1 instead?

Thank you very much

Best Jules

Re: TRansforming a series of Reals into a series of integers

Posted: Tue Nov 15, 2016 3:28 pm
by TomDoan
z{0} means the current value of the series represented by z. z{1} means the first lag.

See Chapter 6 in the RATS Programming Manual.