Interpolation

For requesting general information about EViews, sharing your own tips and tricks, and information on EViews training or guides.

Moderators: EViews Gareth, EViews Moderator

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

Interpolation

Postby EViews Gareth » Thu Mar 12, 2009 11:45 am

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)
Follow us on Twitter @IHSEViews

fnarita
Posts: 15
Joined: Thu Jun 04, 2009 11:15 am

Re: Interpolation

Postby fnarita » Wed Jun 10, 2009 2:42 pm

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

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

Re: Interpolation

Postby EViews Gareth » Wed Jun 10, 2009 3:03 pm

Yep, I'd noticed that, but forgot to update the notation in the original post.
Follow us on Twitter @IHSEViews

fnarita
Posts: 15
Joined: Thu Jun 04, 2009 11:15 am

Re: Interpolation

Postby fnarita » Thu Jun 11, 2009 8:22 am

I see how it went. Anyway, thank you very much!! :D
Futoshi

shm83
Posts: 35
Joined: Tue Sep 10, 2013 5:00 am

Re: Interpolation

Postby shm83 » Fri Sep 13, 2013 3:11 am

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.

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

Re: Interpolation

Postby EViews Gareth » Fri Sep 13, 2013 8:04 am

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.
Follow us on Twitter @IHSEViews

shm83
Posts: 35
Joined: Tue Sep 10, 2013 5:00 am

Re: Interpolation

Postby shm83 » Fri Sep 13, 2013 12:37 pm

Would It work with Eviews 7? I'll try It on Monday

shm83
Posts: 35
Joined: Tue Sep 10, 2013 5:00 am

Re: Interpolation

Postby shm83 » Sun Sep 15, 2013 11:24 pm

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

afzuch
Posts: 1
Joined: Mon Aug 10, 2015 10:30 pm

Re: Interpolation

Postby afzuch » Mon Aug 10, 2015 10:46 pm

I use Eviews *
where can I put those codes? can u explain step by step?
I'm new with Eviews

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

Re: Interpolation

Postby EViews Gareth » Tue Aug 11, 2015 6:37 am

File->new->program
Follow us on Twitter @IHSEViews


Return to “General Information and Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 22 guests