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
looping through an alpha series
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
-
- EViews Developer
- Posts: 564
- Joined: Thu Apr 25, 2013 7:48 pm
Re: looping through an alpha series
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,
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,
Or by looping over an equivalent svector,
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
Re: looping through an alpha series
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
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
Re: looping through an alpha series
I figured it out.
It works when i convert the ith element into a string or temporary string, then use it
It works when i convert the ith element into a string or temporary string, then use it
-
- EViews Developer
- Posts: 564
- Joined: Thu Apr 25, 2013 7:48 pm
Re: looping through an alpha series
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.
Who is online
Users browsing this forum: No registered users and 35 guests