Hi all,
I am a new Eviews user. I have 14 variables names with the same pattern. They all start with "d_", e.g. d_capacity, d_trade, d_gdp, etc. I need to do "scalar sum = @sum(d_capacity)
scalar sum = @sum(d_trade)
scalar sum = @sum(d_gdp)
..."
for all these 14 variables. Is there a way to carry out this calculation in a loop?
A hint would be helpful. Thanks
how to run function for variables starting with the same letter
Moderators: EViews Gareth, EViews Moderator
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13319
- Joined: Tue Sep 16, 2008 5:38 pm
Re: how to run function for variables starting with the same letter
File->New Program, then write the following and hit Run
Code: Select all
for %j capacity trade gdp
scalar sum_{%j} = @sum(d_{%j})
next
Follow us on Twitter @IHSEViews
Re: how to run function for variables starting with the same letter
Thanks Gareth!
Is there in Eviews a way expressing "for `var' in varlist" as in stata?
I am trying to fill these scalars into a vector or a matrix.
But it seems that the following code doesn't work. I think it is because Eviews needs the scalar to have specific numbering.
vector(3) n_obs
for %j capacity trade gdp
n_obs.fill = sum_{%j}
next
Is there in Eviews a way expressing "for `var' in varlist" as in stata?
I am trying to fill these scalars into a vector or a matrix.
But it seems that the following code doesn't work. I think it is because Eviews needs the scalar to have specific numbering.
vector(3) n_obs
for %j capacity trade gdp
n_obs.fill = sum_{%j}
next
-
- EViews Developer
- Posts: 2672
- Joined: Wed Oct 15, 2008 9:17 am
Re: how to run function for variables starting with the same letter
I may be missing something, but it seems to me as though you want something like
There's another way of doing this by loading the elements into a svector. I prefer it in this case since you don't have to increment the !i in the loop yourself.
Code: Select all
vector(3) n_obs
!i = 1
for %j d_capacity d_trade d_gdp
n_obs(!i) = @sum({%j})
!i = !i + 1
next
There's another way of doing this by loading the elements into a svector. I prefer it in this case since you don't have to increment the !i in the loop yourself.
Code: Select all
svector list = @wsplit("d_capacity d_trade d_gdp")
vector(@rows(list)) n_obs
for !i = 1 to @rows(list)
%name = list(!i)
n_obs(!i) = @sum({%name})
next
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13319
- Joined: Tue Sep 16, 2008 5:38 pm
Re: how to run function for variables starting with the same letter
I prefer:
Code: Select all
%list = "d_capacity d_trade d_gdp"
for !i = 1 to @wcount(%list)
%name = @word(%list, !i)
n_obs(!i) = @sum({%name})
next
Follow us on Twitter @IHSEViews
Re: how to run function for variables starting with the same letter
Thanks Glenn and Gareth!
Return to “General Information and Tips and Tricks”
Who is online
Users browsing this forum: No registered users and 20 guests