Finding common last observation in workfile

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

javiersan
Posts: 184
Joined: Mon Jan 19, 2009 8:18 am

Finding common last observation in workfile

Postby javiersan » Fri Nov 05, 2010 2:57 am

Hello,

I wonder if there is a way of finding the last date that has a non-na observation for all the series in a workfile (or group).

At the moment this can be achieved by the following convoluted commands:

Code: Select all

group g * series tracklast=@recode(@rnas(g)=0,na,@rnas(g)) !lastv=@ifirst(tracklast)-1 %last_dt=@otod(!lastv) smpl {%last_dt} {%last_dt}
Is there a more elegant code that achieves the same result?

Thanks,

Javier

javiersan
Posts: 184
Joined: Mon Jan 19, 2009 8:18 am

Re: Finding common last observation in workfile

Postby javiersan » Fri Nov 05, 2010 3:18 am

Actually, the code only works if the series have no gaps, so for most cases it may have to be modified.

Javier

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: Finding common last observation in workfile

Postby trubador » Fri Nov 05, 2010 4:22 am

There is more than one way to do that. Here is one:

Code: Select all

!nseries = my_group.@count vector(!nseries) datevals svector(!nseries) datestrs for !i = 1 to !nseries %name = gr.@seriesname(!i) datestrs(!i) = {%name}.@last 'Dates will be stored in string format and you can keep this as a list for further use datevals(!i) = @dateval({%name}.@last) 'Dates will be stored in number format to find the latest one next %last = @datestr(@max(dates)) smpl {%last} {%last}

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

Re: Finding common last observation in workfile

Postby EViews Gareth » Fri Nov 05, 2010 7:17 am

I'm posting from my phone, so can't test this, but something along the lines of:

Code: Select all

smpl if @robs(g)>0 series t = @trend+1 string date = @otod(@max(t))

javiersan
Posts: 184
Joined: Mon Jan 19, 2009 8:18 am

Re: Finding common last observation in workfile

Postby javiersan » Fri Nov 05, 2010 8:42 am

It does work with the following variation:

Code: Select all

smpl if @robs(g)=g.@count series t = @trend+1 string date = @otod(@max(t))
Thanks,

Javier

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

Re: Finding common last observation in workfile

Postby EViews Gareth » Fri Nov 05, 2010 8:48 am

Ah, yes, I misunderstood whether you wanted the last date for which any series has a value or the last date for which all series have a value.

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

Re: Finding common last observation in workfile

Postby EViews Glenn » Fri Nov 05, 2010 10:10 am

Or more directly

Code: Select all

smpl if @rnas(g)=0


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests