Page 1 of 1
Finding common last observation in workfile
Posted: Fri Nov 05, 2010 2:57 am
by javiersan
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
Re: Finding common last observation in workfile
Posted: Fri Nov 05, 2010 3:18 am
by javiersan
Actually, the code only works if the series have no gaps, so for most cases it may have to be modified.
Javier
Re: Finding common last observation in workfile
Posted: Fri Nov 05, 2010 4:22 am
by trubador
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}
Re: Finding common last observation in workfile
Posted: Fri Nov 05, 2010 7:17 am
by EViews Gareth
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))
Re: Finding common last observation in workfile
Posted: Fri Nov 05, 2010 8:42 am
by javiersan
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
Re: Finding common last observation in workfile
Posted: Fri Nov 05, 2010 8:48 am
by EViews Gareth
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.
Re: Finding common last observation in workfile
Posted: Fri Nov 05, 2010 10:10 am
by EViews Glenn