Unexpected result with function @datediff

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

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

Unexpected result with function @datediff

Postby mamo » Tue Aug 04, 2026 2:53 am

Dear Eviews team,
I am using Eviews 14, Jun 16 2026 build.
I obtain an unexpected result with the function @datediff, see attached code.
I would have expected the series lag1 and lag 2 to show identical values all over. In fact, that is the case only in leap years
Can you explain why the series lag1 and lag 2 do not have identical values in all years except in leap years?
Best, mamo

Code: Select all

wfcreate dd 2000 2020 ' create annual lag series lag1=@datediff(@date, @dateadd(@date,1,"A"), "dd") ' crate lagged date series, lagged by one year series date_lagged=@date(lag1) ' create 2nd lag, as day-difference between @date and lagged date series series lag2=@datediff(date_lagged, @date, "dd") ' set sample to exclude NAs smpl 2001 @last ' if @month=1 and @day=1 ' define group with the two lag-series group gr lag1 lag2 ' show the group and the difference between the two lage series gr.sheet(c)

EViews Matt
EViews Developer
Posts: 592
Joined: Thu Apr 25, 2013 7:48 pm

Re: Unexpected result with function @datediff

Postby EViews Matt » Tue Aug 04, 2026 1:35 pm

Hello,

The confusion actually originates from the expression @date(lag1), not the @datediff function. "Dynamic" per-observation lags are only available for series (and perhaps some special cases I don't recall at the moment). Instead of raising an error, EViews is just using the first value of the lag1 series, -366, for all observations, so the expression is equivalent to @date(-366). No surprise then that series lag2 is full of -366.

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

Re: Unexpected result with function @datediff

Postby mamo » Wed Aug 05, 2026 4:35 am

Many thanks, very clear!
So in line with your reply, the following works as expected, i.e. lag1 = lag2

Code: Select all

wfcreate dd 2000 2020 ' create annual lag series lag1=@datediff(@date, @dateadd(@date,1,"A"), "dd") ' crate lagged date series, lagged by one year series dat=@date ' series date_lagged=@date(lag1) series dat_lagged=dat(lag1) ' create 2nd lag, as day-difference between @date and lagged date series ' series lag2=@datediff(date_lagged, @date, "dd") series lag2=@datediff(dat_lagged, dat, "dd") ' set sample to exclude NAs smpl 2001 @last ' if @month=1 and @day=1 ' define group with the two lag-series group gr lag1 lag2 ' show the group and the difference between the two lage series gr.sheet(c)


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 2 guests