basic problem

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator

karakilamaravilla
Posts: 24
Joined: Tue Jun 13, 2017 12:04 pm

basic problem

Postby karakilamaravilla » Fri Jun 16, 2017 11:00 pm

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: 560
Joined: Thu Apr 25, 2013 7:48 pm

Re: basic problem

Postby EViews Matt » Sat Jun 17, 2017 6:46 am

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

Postby karakilamaravilla » Sat Jun 17, 2017 7:45 am

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 Matt
EViews Developer
Posts: 560
Joined: Thu Apr 25, 2013 7:48 pm

Re: basic problem

Postby EViews Matt » Sat Jun 17, 2017 8:31 am

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

karakilamaravilla
Posts: 24
Joined: Tue Jun 13, 2017 12:04 pm

Re: basic problem

Postby karakilamaravilla » Sat Jun 17, 2017 8:57 am

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 Matt
EViews Developer
Posts: 560
Joined: Thu Apr 25, 2013 7:48 pm

Re: basic problem

Postby EViews Matt » Sat Jun 17, 2017 9:13 am

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

Postby karakilamaravilla » Sat Jun 17, 2017 10:21 am

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!


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 20 guests