Page 1 of 1

Unexpected result with function @datediff

Posted: Tue Aug 04, 2026 2:53 am
by mamo
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)

Re: Unexpected result with function @datediff

Posted: Tue Aug 04, 2026 1:35 pm
by EViews Matt
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.

Re: Unexpected result with function @datediff

Posted: Wed Aug 05, 2026 4:35 am
by mamo
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)