TRansforming a series of Reals into a series of integers

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
Jules89
Posts: 140
Joined: Thu Jul 14, 2016 5:32 am

TRansforming a series of Reals into a series of integers

Unread post 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
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

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

Unread post by TomDoan »

You want

gset lag = fix(z{0})

z by itself (in this context) is just the "handle" to the series.
Jules89
Posts: 140
Joined: Thu Jul 14, 2016 5:32 am

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

Unread post 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
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

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

Unread post 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.
Post Reply