Index problem in while loop

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

morak5
Posts: 16
Joined: Thu Jan 16, 2014 2:19 pm

Index problem in while loop

Postby morak5 » Fri Dec 16, 2016 2:17 pm

Hi,

I have a vector j1 = [1 2 3, ..., 17] and a set of series labelled w_0, w_5, w_10, ..., w_80, and want to create a new series

jp1 = w_0*j1(1) + w_5*j1(2) + ... + w_80*j1(17)

The code below however, generates jp1 starting from !m=12 (!n=55), instead of !m=1. What am I doing wrong here? Thanks.

Code: Select all

scalar J= 17 ' Number of age groups between 0 to 80+ vector(J) j1 for !k = 1 to J j1(!k) = !k next series jp1 = 0 !m=0 while !m<17 !n = 5*!m !m = !m + 1 jp1 = w_{!n}*j1(!m) + jp1 wend

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

Re: Index problem in while loop

Postby EViews Gareth » Fri Dec 16, 2016 2:28 pm

Your code is correct. What makes you think it isn't?

EViews Matt
EViews Developer
Posts: 583
Joined: Thu Apr 25, 2013 7:48 pm

Re: Index problem in while loop

Postby EViews Matt » Fri Dec 16, 2016 2:56 pm

If you're looking at the modification history shown within the series, be aware that it's limited to six lines. It's therefore normal that you would only see a record of the last six assignments within your loop, corresponding to !m = 12 through !m = 17.

morak5
Posts: 16
Joined: Thu Jan 16, 2014 2:19 pm

Re: Index problem in while loop

Postby morak5 » Fri Dec 16, 2016 3:08 pm

Ah, I see. Just checked the numbers and you are right. Many thanks, Matt, Gareth.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests