Fractional Differencing

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

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

Fractional Differencing

Postby trubador » Fri Nov 26, 2010 8:44 am

Below is a program to carry out fractional differencing as well as regular and seasonal differencing. Although regular and seasonal differences can be used consecutively, they cannot be combined with fractional difference. Please feel free to optimize and improve the code...

Code: Select all

'Fractional Differencing Program (also allows for Regular and Seasonal Differencing)
'Reference: Diebold, F. X. and Rudebusch, G. D. (1989), “Long Memory and Persistence in Aggregate Output”, Journal of Monetary Economics, Vol. 24, pp. 189-209.

call difference

subroutine difference
!result = 0
!choice=2
!result=@uidialog("caption","Fractional and Regular Differencing","text","Regular and Seasonal Differences cannot be combined with Fractional Difference!","edit",%name,"Name of your series","edit",%diff,"Degree of differencing","edit",%sdiff,"Degree of seasonal differencing (Optional)","Radio", !choice,"Would you like to save the coefficients?","Yes No" )
if !result=-1 then
   stop
endif

if @isempty(%diff)=1 and @isempty(%sdiff)=1 then
 stop
 else if @isempty(%diff)=1 and @isempty(%sdiff)=0 then
   !s = @val(%sdiff)
   series {%name}_diff = d({%name},0,!s)
   stop
  endif
endif

if @isempty(%sdiff)=0 then
   !s = @val(%sdiff)
else
   !s=0
endif

if @val(%diff) = 0 then
  !d = 1
else
  !d = @val(%diff)
endif

series {%name}_diff
series {%name}_coeffs
call fracdiff({%name},!d,!s,{%name}_diff,{%name}_coeffs)

if !choice = 2 then
   delete {%name}_coeffs
endif

endsub

subroutine local fracdiff(series y,scalar fd,scalar sd,series yd,series yc)

  if fd>0 and @floor(fd) = fd then
   yd = d(y,fd,sd)
   return
  endif

  !nobs = @obs(y)
  %beg = y.@first
  %end = y.@last
  !first = @dtoo(y.@first)

  smpl %beg %end
  series yc = 1
  yc = @cumsum(yc)
  series yd = 0

  smpl %beg+1 %end
  yc = @cumprod((yc-fd-2)/(yc-1))
  smpl @all

  for !i=1 to !nobs
   for !j = 1 to !i
     yd(!i+!first-1) = yd(!i+!first-1) + yc(!j+!first-1)*y(!i-!j+!first)
   next
  next

endsub

Return to “Program Repository”

Who is online

Users browsing this forum: No registered users and 1 guest