Interpolate if gap is not larger than 3 obs

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

strypste
Posts: 53
Joined: Tue Jan 24, 2012 8:54 am

Interpolate if gap is not larger than 3 obs

Postby strypste » Thu Nov 19, 2015 9:53 am

Dear All

I want to interpolate a series but it can only interpolate if the number of missing observation is 3 or smaller.

So for example if I have a series like this:

14.6301
NA
NA
16.969
NA
NA
NA
NA
NA
18.4762
20.5717

then the command should interpolate the first gap but not the second gap.

Any ideas?

Best
s

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

Re: Interpolate if gap is not larger than 3 obs

Postby EViews Gareth » Thu Nov 19, 2015 10:29 am

There's nothing built in that will do it. You'll have to write a program.

Luckily I found an ancient program that I wrote that performs simple linear interpolation on up to 2 missing values in a row. Should be fairly straight forward to add an additional 3rd.

Code: Select all

create u 100 rndseed 1 series y=nrnd smpl if nrnd>0.8 y = na smpl @all series temp=y 'interpolation of two missings smpl if y = na and y(1) = na temp = (y(-1) + y(2))/3 smpl if y=na and y(-1) = na temp = (y(-2)+y(1))*2/3 'interpolation of a single missing smpl if y = na and temp=na temp = (y(-1)+y(+1))/2 smpl @all show temp y

strypste
Posts: 53
Joined: Tue Jan 24, 2012 8:54 am

Re: Interpolate if gap is not larger than 3 obs

Postby strypste » Thu Nov 19, 2015 10:38 am

Thanks for providing the program.

Cheers

strypste
Posts: 53
Joined: Tue Jan 24, 2012 8:54 am

Re: Interpolate if gap is not larger than 3 obs

Postby strypste » Thu Nov 19, 2015 11:34 am

I think there was a small error in the code related to the interpolation of two gaps... The following code produces exactly the same as the ipolate command.

Code: Select all

create u 100 rndseed 1 series y=nrnd smpl if nrnd>0.8 y = na smpl @all series temp=y ' Interpolate y with the built in command (so this will also fill gaps larger than 2) y.ipolate y_i 'interpolation of two missings ' first missing smpl if y = na and y(1) = na temp = (2*y(-1) + y(2))/3 ' This is slightly different compared to previous code ' second missing smpl if y=na and y(-1) = na temp = (y(-2)+2*y(1))/3 ' This is slightly different compared to previous code 'interpolation of a single missing smpl if y = na and temp=na temp = (y(-1)+y(+1))/2 smpl @all show temp y y_i


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 2 guests