Hi,
Is there a command that Eviews displays the n-smallest or n-largest values? (and the corresponding row)
To get the minimum I use @cmin and @cimin, but if I want to have the 5 smallest (largest) values.
Is there a command or is the easiest way to search the minimum, delete it from the vector and search again?
Thanks in advance,
Katjes
Find minimum(s) or maximum(s)
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13602
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Find minimum(s) or maximum(s)
There isn't really any command that will do that, currently.
The only thing you can do is extract the column you're interested in into a vector, sort the vector, and then retrieve the first (or last) 5 values from that vector.
The only thing you can do is extract the column you're interested in into a vector, sort the vector, and then retrieve the first (or last) 5 values from that vector.
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: Find minimum(s) or maximum(s)
It was unclear whether you were talking about getting these values for a series or a vector. If you are talking about doing this from a series, you can do something like:
and
If you want to get them, then you can use Gareth's suggestion to convert into a vector using the stom. If you do it for the subsample, then you'll just get the vector of values you want.
Code: Select all
smpl if @ranks(y)<=5
show @ranks y
Code: Select all
smpl if @ranks(y)>=@obs(y)-4
show @ranks y
Re: Find minimum(s) or maximum(s)
the whole story: I have a scalar for various countries, indicating the spread (%c) between two dates, then I saved the scalar in a vector (each row is assigned to a specific country), and now I want to find the 5 countries with maximum and minimum spread. The sort option is good, but then I don't know which country is associated with the value, because than the row number doesn't correspond to the position of the country (!i) in the loop...
spread(!i)={%c}(@dtoo("07/31/2007"))-{%c}(@dtoo("01/01/2004"))
vector minimum = @sort(spread,"a","i") '(ascending)
vector maximum = @sort(spread,"d","i") '(descending)
Any suggestions?
spread(!i)={%c}(@dtoo("07/31/2007"))-{%c}(@dtoo("01/01/2004"))
vector minimum = @sort(spread,"a","i") '(ascending)
vector maximum = @sort(spread,"d","i") '(descending)
Any suggestions?
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: Find minimum(s) or maximum(s)
You say you have countries and a scalar. What's the structure of your workfile? How was the vector created? And how many elements does it have? There are some slow, brute force ways of doing things that will work, but I wouldn't recommend for very large problems...
Having said that (the non-brute force method):
----
I think, based on limited information, what I'd do if I were you is to create a new workfile page with observations equal to the number of elements in your vector. Then copy the vector to the new workfile page, use mtos to create a series and work from there.
The problem, as you note, in the matrix world is that we can't sort on a column of a matrix so it's difficult to keep track of who is who.
In the workfile world, just create a new variable prior to doing the sort. If you are in the new workfile with THEVEC as the vector:
so that when you sort by the series, the id will get sorted too. Or even better, create a alpha series of labels in the new workfile so that'll get sorted too.
All of this might change depending on the structure of your original workfile. There might be better ways of doing stuff...
Having said that (the non-brute force method):
----
I think, based on limited information, what I'd do if I were you is to create a new workfile page with observations equal to the number of elements in your vector. Then copy the vector to the new workfile page, use mtos to create a series and work from there.
The problem, as you note, in the matrix world is that we can't sort on a column of a matrix so it's difficult to keep track of who is who.
In the workfile world, just create a new variable prior to doing the sort. If you are in the new workfile with THEVEC as the vector:
Code: Select all
series origid = @trend + 1
mtos(thevec, theser)
sort theser
All of this might change depending on the structure of your original workfile. There might be better ways of doing stuff...
Re: Find minimum(s) or maximum(s)
thanks for the code, the long-version which gives the right results looks as follows:
vector(!c) spread 'where !c is the number of countries
For !i=1 to !c
%c = countries.@seriesname(!i) '%c identifies the interest rate for each country, named by each country (e.g. US, GER,...)
spread(!i)={%c}(@dtoo("12/31/2008"))-{%c}(@dtoo("08/01/2007"))
'create a new page for calculation
pagecreate(page= maximum) u !c
series origid = @trend + 1 'this gives the country id and identifys the countries after the sorting below
copy page1\spread maximum\
mtos(spread, spreadser)
sort spreadser
stom(origid, minimum) 'this sorts the country number from minimum to maximum according to the minimum/maximum..
copy maximum\minimum page1\
pagedelete maximum
pageselect page1
group minimums
group maximums
for !k=1 to 5 ' number of minimums/maximums (5 countries with the smallest/largest spreads)
for !i=1 to !c
%c = countries.@seriesname(!i)
if minimum(!k)=!i then minimums.add {%c} 'where %c is the name of the country variable
else if minimum(!c+1-!k)=!i then maximums.add {%c}
endif
endif
next ' next country
next ' next minimum/maximum
Who is online
Users browsing this forum: No registered users and 2 guests
