## basic problem

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.
karakilamaravilla
Posts: 24
Joined: Tue Jun 13, 2017 12:04 pm

### basic problem

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!

EViews Matt
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.

karakilamaravilla
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?

!iden = 0
for !i =1 to 16
for !c=1 to 84
if __best model(!c, 1) = !i then
!iden = 1 + !iden
endif
next
next

EViews Matt
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) __resultadosfor !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) = !idennext`

karakilamaravilla
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) __resultadosfor !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) = !idennext`

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 Matt
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)".

karakilamaravilla
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!