looping through an alpha series

For questions regarding programming in the EViews programming language.

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

amrsherif
Posts: 99
Joined: Mon Jul 23, 2018 4:34 pm

looping through an alpha series

Postby amrsherif » Wed Feb 03, 2021 3:33 pm

Hi,

This seems very basic, but i am unabnle to loop through the elements of an alpha series.
I have an alpha series with names of series that i want to fetch.
How can i loop through them so i can add them to a string?

See attached photo for an example of what the series looks like

I have tried:
1) for %series in alpha_series_name
2) for !i=1 to @ilast(alpha_series_name)
3) i've also converted it into an svector but could still not access the elements in that

Thanks

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

Re: looping through an alpha series

Postby EViews Matt » Wed Feb 03, 2021 4:55 pm

Hello,

If what you're ultimately after is a string containing the data in an alpha series, you can generate that with a single expression,

Code: Select all

%names = @wjoin(@convert(alpha_series_name))

Otherwise, if you actually need to loop through the alpha series to perform other work, you can in a number of ways. For example, looping over observations,

Code: Select all

for !i = @ifirst(alpha_series_name) to @ilast(alpha_series_name)
     ... alpha_series_name(!i) ...
next

Or by looping over an equivalent svector,

Code: Select all

svector tmp
stom(alpha_series_name, tmp)
for !i = 1 to @rows(tmp)
     ... tmp(!i) ...
next

amrsherif
Posts: 99
Joined: Mon Jul 23, 2018 4:34 pm

Re: looping through an alpha series

Postby amrsherif » Thu Feb 04, 2021 6:17 am

This is strange, I have looped through alpha series many times before, but i cannot get this one to work.

I have tried this:

svector tmp
stom(alpha_series_name, tmp)
for !i = 1 to @rows(tmp)
show tmp(!i)
next

No luck
TMP(1) is not defined in show tmp(1)


WHen i tried this:
for !i = @ifirst(alpha_series_name) to @ilast(alpha_series_name)
show alpha_series_name(!i)
next

it loops through the numbers, but it lags the series by the index, instead of giving the ith element

amrsherif
Posts: 99
Joined: Mon Jul 23, 2018 4:34 pm

Re: looping through an alpha series

Postby amrsherif » Thu Feb 04, 2021 6:22 am

I figured it out.
It works when i convert the ith element into a string or temporary string, then use it

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

Re: looping through an alpha series

Postby EViews Matt » Thu Feb 04, 2021 8:13 am

Right, the show command is predominantly used for displaying entire objects rather than individual elements. As such, ( ) notation is interpreted as lag notation rather than element-of notation. Any normal non-genr expression works as intended, as you discovered.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 29 guests