how can I retrieve the last obersation of a series

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason

reep
Posts: 14
Joined: Fri Jan 27, 2012 2:24 am

how can I retrieve the last obersation of a series

Postby reep » Wed Feb 01, 2012 11:44 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13586
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Wed Feb 01, 2012 12:04 pm

Code: Select all

=@last(series)

reep
Posts: 14
Joined: Fri Jan 27, 2012 2:24 am

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

Postby reep » Wed Feb 01, 2012 12:16 pm

Thanks for the quick response.

reep
Posts: 14
Joined: Fri Jan 27, 2012 2:24 am

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

Postby reep » Wed Feb 01, 2012 12:24 pm

Sorry, to bother you again. But how can I now retrieve also the date for this observation in form of string?
Thanks.

reep
Posts: 14
Joined: Fri Jan 27, 2012 2:24 am

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

Postby reep » Wed Feb 01, 2012 12:41 pm

Sorry, one more question.
Why does the following code not work? Do you have an idea?
scalar test = @last({%ser})
Thanks.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

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

Postby EViews Glenn » Wed Feb 01, 2012 1:08 pm

Should work. Works for me.

Code: Select all

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

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

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

Postby EViews Glenn » Wed Feb 01, 2012 1:45 pm

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...

reep
Posts: 14
Joined: Fri Jan 27, 2012 2:24 am

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

Postby reep » Wed Feb 01, 2012 3:01 pm

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13586
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Wed Feb 01, 2012 3:25 pm

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

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

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

Postby EViews Glenn » Wed Feb 01, 2012 4:16 pm

Which is why Gareth lobbied to add it...I forgot about that one.

reep
Posts: 14
Joined: Fri Jan 27, 2012 2:24 am

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

Postby reep » Thu Feb 02, 2012 2:03 am

Thank you. Everything works fine now.

jfgeli
Posts: 72
Joined: Fri Jan 30, 2009 6:29 pm

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

Postby jfgeli » Thu Jan 10, 2013 11:15 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13586
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Thu Jan 10, 2013 11:26 am

Code: Select all

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

jfgeli
Posts: 72
Joined: Fri Jan 30, 2009 6:29 pm

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

Postby jfgeli » Thu Jan 10, 2013 1:14 pm

You make it look so easy...
Thanks a lot!!!


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 1 guest