## Fractional Differencing

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

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

### Fractional Differencing

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 differencesubroutine 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   stopendifif @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  endifendifif @isempty(%sdiff)=0 then   !s = @val(%sdiff)else   !s=0endifif @val(%diff) = 0 then  !d = 1else  !d = @val(%diff)endifseries {%name}_diffseries {%name}_coeffscall fracdiff({%name},!d,!s,{%name}_diff,{%name}_coeffs)if !choice = 2 then   delete {%name}_coeffsendifendsubsubroutine 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  nextendsub`