Page 1 of 1

how can I retrieve the last obersation of a series

Posted: Wed Feb 01, 2012 11:44 am
by reep
How can I retrieve the value of the last observation of a series?
For example one series ends in 2009m12 and the other in 2010m12.
Do you have a code example?
Thanks a lot.
reep

Re: how can I retrieve the last obersation of a series

Posted: Wed Feb 01, 2012 12:04 pm
by EViews Gareth

Code: Select all

=@last(series)

Re: how can I retrieve the last obersation of a series

Posted: Wed Feb 01, 2012 12:16 pm
by reep
Thanks for the quick response.

Re: how can I retrieve the last obersation of a series

Posted: Wed Feb 01, 2012 12:24 pm
by reep
Sorry, to bother you again. But how can I now retrieve also the date for this observation in form of string?
Thanks.

Re: how can I retrieve the last obersation of a series

Posted: Wed Feb 01, 2012 12:41 pm
by reep
Sorry, one more question.
Why does the following code not work? Do you have an idea?
scalar test = @last({%ser})
Thanks.

Re: how can I retrieve the last obersation of a series

Posted: Wed Feb 01, 2012 1:08 pm
by EViews Glenn
Should work. Works for me.

Code: Select all

%ser="ddiftbill3m" scalar test = @last({%ser})

Re: how can I retrieve the last obersation of a series

Posted: Wed Feb 01, 2012 1:45 pm
by EViews Glenn
As to the earlier question about the string representation. This isn't particularly elegant but I think it should work. Give it a test drive.

Code: Select all

%ser="tbill3m" smpl @all scalar lastid = @ilast({%ser})-1 ' get last obs id scalar lastval = @last({%ssr}) ' get last value series dateval = @sum(@date, "@all if @trend=lastid") ' set sample to this obs and get the date number string datestr = @datestr(@max(dateval)) ' get the date string
The @LAST isn't part of this calculation but is there so you can check the value against the observation string. You can delete the temps LASTID and DATEVAL if you want. You can also supply formatting information to the @DATESTR function to format the string the way you want it. There may be better ways to do this...

Re: how can I retrieve the last obersation of a series

Posted: Wed Feb 01, 2012 3:01 pm
by reep
thanks a lot.
I guess the command @last({%ser}) is not working because I haven't updated of Eviews 6 for a while at my work computer. At home it works fine.

Further, I noticed that the functions @last() and @ilast() work with Eviews 6 although they are not described in the command reference. I found a description only in Eviews 7 manual.

Re: how can I retrieve the last obersation of a series

Posted: Wed Feb 01, 2012 3:25 pm
by EViews Gareth
As to the earlier question about the string representation. This isn't particularly elegant but I think it should work. Give it a test drive.

Code: Select all

%ser="tbill3m" smpl @all scalar lastid = @ilast({%ser})-1 ' get last obs id scalar lastval = @last({%ssr}) ' get last value series dateval = @sum(@date, "@all if @trend=lastid") ' set sample to this obs and get the date number string datestr = @datestr(@max(dateval)) ' get the date string
The @LAST isn't part of this calculation but is there so you can check the value against the observation string. You can delete the temps LASTID and DATEVAL if you want. You can also supply formatting information to the @DATESTR function to format the string the way you want it. There may be better ways to do this...
In EViews 7 you can just do:

Code: Select all

string datestr = {%ser}.@last

Re: how can I retrieve the last obersation of a series

Posted: Wed Feb 01, 2012 4:16 pm
by EViews Glenn
Which is why Gareth lobbied to add it...I forgot about that one.

Re: how can I retrieve the last obersation of a series

Posted: Thu Feb 02, 2012 2:03 am
by reep
Thank you. Everything works fine now.

Re: how can I retrieve the last obersation of a series

Posted: Thu Jan 10, 2013 11:15 am
by jfgeli
Hi,
I have similar problem that I cannot solve. I have a series which contains NAs and 1s. For example:
NA
NA
NA
1
NA
1
1
NA
NA
I would like to fill with 1s the series with 1s from the first observation including NA until the last 1s so I will get something like:
1
1
1
1
1
1
NA
NA

I have tried something like smpl 1990.1 @last.series (the page starts in 1990q1 so it is fine) and then series = 1 but it does not like the way I restrict the sample. Which is the correct way of doing of restricting the sample to the last non na.

Thanks a lot.

Fede

Re: how can I retrieve the last obersation of a series

Posted: Thu Jan 10, 2013 11:26 am
by EViews Gareth

Code: Select all

%last = SERIES.@last smpl @first {%last}

Re: how can I retrieve the last obersation of a series

Posted: Thu Jan 10, 2013 1:14 pm
by jfgeli
You make it look so easy...
Thanks a lot!!!