Page 1 of 1
basic problem
Posted: Fri Jun 16, 2017 11:00 pm
by karakilamaravilla
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!
Re: basic problem
Posted: Sat Jun 17, 2017 6:46 am
by EViews Matt
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.
Re: basic problem
Posted: Sat Jun 17, 2017 7:45 am
by karakilamaravilla
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
Re: basic problem
Posted: Sat Jun 17, 2017 8:31 am
by EViews Matt
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
Re: basic problem
Posted: Sat Jun 17, 2017 8:57 am
by karakilamaravilla
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?
Re: basic problem
Posted: Sat Jun 17, 2017 9:13 am
by EViews Matt
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)".
Re: basic problem
Posted: Sat Jun 17, 2017 10:21 am
by karakilamaravilla
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!