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
Interpolate if gap is not larger than 3 obs
Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13585
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Interpolate if gap is not larger than 3 obs
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.
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
Re: Interpolate if gap is not larger than 3 obs
Thanks for providing the program.
Cheers
Cheers
Re: Interpolate if gap is not larger than 3 obs
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
Who is online
Users browsing this forum: No registered users and 2 guests
