Panels: getting date of earliest non-na in variable for a specific cross-sectional unit

For questions regarding programming in the EViews programming language.

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

mamo
Posts: 191
Joined: Wed Nov 07, 2012 9:11 am

Panels: getting date of earliest non-na in variable for a specific cross-sectional unit

Postby mamo » Wed Feb 21, 2018 8:07 am

Dear all,
I amusing Eviews 9.5 Dec 16 built.

Two questions, both assuming that one is working with a panel workfile:
1) Is there a straightforward way of assigning the number of cross sectional units in a panel workpage to a scalar variable ?
2) Is there a straightforward approach of finding the date of the earliest non-missing value in a series for a specific cross sectional unit? One possible approach is implemented in the subroutine "getearliest" in the program listed below. However, it looks to me unnecessarily complicated. Any suggestion for a more straightforward approach much welcome.

Kind regards, mamo

Code: Select all

'create some data
wfcreate q 2000 2017 2
series x=nrnd
'create NAs in x until 2004Q3 for the 2nd cross sectional unit 
smpl @first 2004Q3 if crossid=2
x=na
smpl @all
!notnadate=NA
'get the date of the earliest available non-mising value in x for the 2nd cross sectional unit 
call getearliest(x, "crossid", "2", !notnadate)
'show in the statusline the earliest non-missing date for the 2nd cross sectional unit
%notnadate=@datestr(!notnadate, "YYYY[Q]Q")
statusline %notnadate

subroutine getearliest(series v, string %crossidentifier, string %cid, scalar !dat)
'gets the date of the earliest available non-mising value in v cross sectional unit  labelled %cid
' in the series or alpha %crossidentifier identifying the cross secional units
'and writes into the string variable "%dat"
%oldsmpl=@pagesmpl
if {%crossidentifier}.@type="SERIES" then
   smpl @all if {%crossidentifier}={%cid}
else
   if {%crossidentifier}.@type="ALPHA" then
      smpl @all if {%crossidentifier}=@stripquotes(%cid)
   endif
endif
vector(1) _$ndates
series _$$ndates=@max(@cellid, @all)
stom(_$$ndates, _$ndates)
!t1=@ifirst(v)-(_$ndates(1)*(@floor(@ifirst(v)/_$ndates(1))))
delete _$ndates _$$ndates
series _$t2=@date(!t1-1)
vector(1) _$t3
stom(_$t2, _$t3)
!dat =_$t3(1)
delete _$t2   _$t3
smpl {%oldsmpl}
endsub

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

Re: Panels: getting date of earliest non-na in variable for a specific cross-sectional unit

Postby EViews Gareth » Wed Feb 21, 2018 9:03 am

1)

Code: Select all

series _cross = @crossid
scalar numcross = @max(_cross)


2)

Code: Select all

smpl if @crossid=3
string date = @otod(@ifirst(y))
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 29 guests