Hello
I need help with the following:
If I have a matrix (n, 1). Where each pair (n, 1) corresponds to only 5 possible numbers.
I need to create an array of (5, 2) where the rows of the first column are the identifiers (ie the 5 possible numbers) and the rows of the second column are the number of times those identifiers appear in the matrix , 1).
How can I do it?
Thank you very much!
basic problem
Moderators: EViews Gareth, EViews Steve, EViews Jason, EViews Moderator, EViews Pamela

 EViews Developer
 Posts: 256
 Joined: Thu Apr 25, 2013 7:48 pm
Re: basic problem
Hello,
You can use @uniquevals to produce a vector of unique values in your matrix. You can then loop through your matrix and the unique values to count their individual frequencies.
You can use @uniquevals to produce a vector of unique values in your matrix. You can then loop through your matrix and the unique values to count their individual frequencies.

 Posts: 24
 Joined: Tue Jun 13, 2017 12:04 pm
Re: basic problem
EViews Matt wrote:Hello,
You can use @uniquevals to produce a vector of unique values in your matrix. You can then loop through your matrix and the unique values to count their individual frequencies.
Thanks Matt
How could I make something like this work?
matrix __resultados = @sort(@uniquevals(__best_model),"a")
matrix(16, 2) __resultados
!iden = 0
for !i =1 to 16
for !c=1 to 84
if __best model(!c, 1) = !i then
!iden = 1 + !iden
endif
__resultados(!i, 2) = %iden
next
next

 EViews Developer
 Posts: 256
 Joined: Thu Apr 25, 2013 7:48 pm
Re: basic problem
You've got the right idea. Here are a few changes:
Code: Select all
matrix __resultados = @sort(@uniquevals(__best_model),"a")
matrix(__resultados.@rows, 2) __resultados
for !i = 1 to __resultados.@rows
!iden = 0
for !c = 1 to @obsrange
if @elem(__best_model, @str(!c)) = __resultados(!i, 1) then
!iden = 1 + !iden
endif
next
__resultados(!i, 2) = !iden
next

 Posts: 24
 Joined: Tue Jun 13, 2017 12:04 pm
Re: basic problem
EViews Matt wrote:You've got the right idea. Here are a few changes:Code: Select all
matrix __resultados = @sort(@uniquevals(__best_model),"a")
matrix(__resultados.@rows, 2) __resultados
for !i = 1 to __resultados.@rows
!iden = 0
for !c = 1 to @obsrange
if @elem(__best_model, @str(!c)) = __resultados(!i, 1) then
!iden = 1 + !iden
endif
next
__resultados(!i, 2) = !iden
next
Your code throws me the following error:
Matrix "__best_model" sent to a function which is expecting a series in "if @elem(__best_model, @str(1)) = _resultados(1, 1) then"
Is this caused by the @elem?

 EViews Developer
 Posts: 256
 Joined: Thu Apr 25, 2013 7:48 pm
Re: basic problem
Oops, when testing I used a series instead of a matrix and forgot to change the syntax back. Replace "@elem(__best_model, @str(!c))" with what you had originally, "__best model(!c, 1)".

 Posts: 24
 Joined: Tue Jun 13, 2017 12:04 pm
Re: basic problem
EViews Matt wrote:Oops, when testing I used a series instead of a matrix and forgot to change the syntax back. Replace "@elem(__best_model, @str(!c))" with what you had originally, "__best model(!c, 1)".
Thanks Matt
The difference was clear to me!
Who is online
Users browsing this forum: No registered users and 3 guests