Hello mboll,
The way Eviews work, I really wouldn't recommend storing values in lists (it is, however, well suited for storing series-names when writing program code, as you already seem to be doing.)
Regardless, here's first a couple of comments on your code, then a couple of alternatives on how to solve your problem.
Some comments:
- In your loop, %i will be overwritten for each iteration. It isn't assigned a unique name. Going through the example-codes below, you might better understand what I mean, and see how to store your results for each iteration.
- @Mean will return a scalar/numeric value, and you therefore cannot use "%". Instead use: "!", as in "!i" instead of "%i" in your loop.
- @Mean({%j}, 2000 2022): When wanting to look closer at a spesific time interval, I suggest you use "smpl" - see below how I usually do it. I'm actually not aware of any other way of doing this.
Alternatives on how to solve:
Here's an example on how to solve it (without using group). From your code, I assume you want an average for each series.
Code: Select all
%Qfp = "x1 x2 x3 x4"
smpl 2000 2022
For %j {%Qfp}
genr {%j}_mean = @Mean({%j})
Next
smpl @all
First I use "smpl" to indicate the period I am interested in when calculating mean. Notice that after the loop is finished, I return to view the whole dataset with "smpl @all".
Then, in the loop, I generate a series for each mean, thus storing the result. I use "genr {%j}_mean" to create a unique series-name, but this could as well been written as "genr mean_{%j}", or for that matter, "genr me{%j}an". Note that the value in the series will be a constant.
Here's the code for storing it in a %-string.
As a sidenote, I struggle to see the use of this (except perhaps if you're trying to make a program that eventually spits out a text-file of some sort.)
Code: Select all
smpl 2000 2022
%templist = ""
For %j {%Qfp}
!i = @Mean({%j})
%templist = %templist + " " + @str(!i)
Next
smpl @all
string listedmeans = @trim(%templist)
Here, in order to store the scalar "!i" for each iteration, I need to generate an empty string-list, "%templist", before starting the For-loop. Then I iteratively add the scalar to the list. After exiting the loop, I use "@trim(%templist)" to get rid of a blank space at the start of the string, and put it into a string-object, "string listedmeans", in case you wanted to view the result.
Following Gareth's interpretation of row-wise mean for all the series in %Qfp, here's some code covering his suggestion:
Code: Select all
group groupname {qfp}
genr meanseriesname = @rmean(groupname)
Hope this was helpful for learning a bit more about Eviews.