Page 1 of 1

Interpolation

Posted: Thu Mar 12, 2009 11:45 am
by EViews Gareth
Unfortunately EViews doesn't (currently) have any interpolation methods to "fill in" NAs within a series. Although we do offer methods when doing frequency conversion, there is not a strict interpolation method.

However, with a bit of programming wizardy, you can do linear interpolation of NAs quite simply:

Code: Select all

series id = @cumsum(x<>NA) series xprev = @sumsby(x, id(-1)) 'value of X before NAs series xnext = @sumsby(x, id) 'value of X after NAs series lambda = (@obsid - @minsby(@obsid, id)) / @sumsby(1, id) 'how many NAs up to now in sequence series x_interpol = lambda*xprev+(1-lambda)*xnext 'interpolated values show x x_interpol
where X is the name of the series you wish to interpolate.

To perform log-linear interpolation you could just log X before hand, and then exp the resultant series afterwards (of course you need to ensure that X is strictly positive)

Re: Interpolation

Posted: Wed Jun 10, 2009 2:42 pm
by fnarita
Dear QMS Gareth,

I used this routine, and it works well! Thank you very much!

By the way, although it works well, I found mis-notation of variables in this program.

For xprev and xnext, you wrote

Code: Select all

series xprev = @sumsby(x, id(-1)) 'value of X before NAs series xnext = @sumsby(x, id) 'value of X after NAs
But, in fact, xprev contains the value of X after NAs, and xnext contains the value of X before NAs, as far as I checked with my work file. So, the notations are flipped for these two variables.

Anyway, the algorithm is very cool, and has saved my time a lot!
Again, thank you so much,
Futoshi

Re: Interpolation

Posted: Wed Jun 10, 2009 3:03 pm
by EViews Gareth
Yep, I'd noticed that, but forgot to update the notation in the original post.

Re: Interpolation

Posted: Thu Jun 11, 2009 8:22 am
by fnarita
I see how it went. Anyway, thank you very much!! :D
Futoshi

Re: Interpolation

Posted: Fri Sep 13, 2013 3:11 am
by shm83
Hi to all!

I have a question/issue. Lets say I want (1) all the first NAs until the first observation filled with this value, and (2) all the NAs at the end of the series filled with the value of the last observation.

Following the notation used in this post, (2) works with this code:

Code: Select all

scalar NumObs NumObs = 100 scalar MaxObs MaxObs=@max(id) for !ii= 1 to NumObs-1 ' Being NumObs the lenght of the series (number of observations + NAs). Defined earlier, lets say 100 here. if id(!ii)=MaxObs then x_interpol(!ii+1)=x_interpol(!ii) endif next
I tried (1) with:

Code: Select all

for !kk = NumObs to 1 if id(!kk)=0 then x_interpol(!kk)=x_interpol(!kk+1) endif next
The program runs without errors, but it does not fill the last NAs :/

How could I make it work?

Thanks in advance!

PS I know this post would fit better in the Programming Board, but as it is related to this thread I thought It would be better to post here than to open a new thread.

Re: Interpolation

Posted: Fri Sep 13, 2013 8:04 am
by EViews Gareth
This post is quite old, and was based on things available in EViews 6...

If you're using EViews 8, I'd just do this:

Code: Select all

!first = @first(x) !last = @last(x) %first = @otod(@ifirst(x)-1) %last = @otod(@ilast(x)+1) smpl @first {%first} x = !first smpl {%last} @last x = !last
Where X is the name of the series.

Re: Interpolation

Posted: Fri Sep 13, 2013 12:37 pm
by shm83
Would It work with Eviews 7? I'll try It on Monday

Re: Interpolation

Posted: Sun Sep 15, 2013 11:24 pm
by shm83

Code: Select all

for !kk = NumObs to 1 step -1 if id(!kk)=0 then x_interpol(!kk)=x_interpol(!kk+1) endif next
It was esasier :/ just adding the "step -1" it works

I will also try your way though.

Thank you Gareth

Re: Interpolation

Posted: Mon Aug 10, 2015 10:46 pm
by afzuch
I use Eviews *
where can I put those codes? can u explain step by step?
I'm new with Eviews

Re: Interpolation

Posted: Tue Aug 11, 2015 6:37 am
by EViews Gareth
File->new->program