extract column label/identifier from matrix

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

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

vytama
Posts: 72
Joined: Wed Dec 19, 2012 11:05 am

extract column label/identifier from matrix

Postby vytama » Thu Dec 11, 2014 7:32 am

Hello, I have a matrix with 48 columns and I have set labels for each column. I want to pull 30 random columns based on certain criteria (for instance, C1, C3, C4, C5, C10, etc.) from original matrix using @hcat function and place these columns in the new matrix. How can extract label or column identifier (c1, c3, etc) to keep track which columns were selected from original matrix? Thank you, Eviews 8.0

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: extract column label/identifier from matrix

Postby EViews Gareth » Thu Dec 11, 2014 10:09 am

I don't think you can. Perhaps add a row to the top of the matrix containing a column number?

vytama
Posts: 72
Joined: Wed Dec 19, 2012 11:05 am

Re: extract column label/identifier from matrix

Postby vytama » Thu Dec 11, 2014 11:11 am

thank you. What is the best way to do that?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: extract column label/identifier from matrix

Postby EViews Gareth » Thu Dec 11, 2014 11:15 am

Make an empty vector of the right size. Loop over the elements of the vector, putting in the column numbers, then use the @vcat function to add that row to the top of the matrix.

vytama
Posts: 72
Joined: Wed Dec 19, 2012 11:05 am

Re: extract column label/identifier from matrix

Postby vytama » Thu Dec 11, 2014 12:30 pm

Thank you, it almost worked. If I use !z=48 for !j=1 to !z, for some reason it includes zero at the first column (then columns go to 49 instead of 48) and then vector and matrix columns do not match. How can I get rid of first value of 0?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: extract column label/identifier from matrix

Postby EViews Gareth » Thu Dec 11, 2014 12:32 pm

Add 1?

vytama
Posts: 72
Joined: Wed Dec 19, 2012 11:05 am

Re: extract column label/identifier from matrix

Postby vytama » Thu Dec 11, 2014 12:58 pm

no, the vector jumps from 0 to 2,3, 4 etc. still keeps 0 in the first column and counts to 49 columns

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: extract column label/identifier from matrix

Postby EViews Gareth » Thu Dec 11, 2014 1:00 pm

I'd need to see the full code to figure out what you're doing wrong.

vytama
Posts: 72
Joined: Wed Dec 19, 2012 11:05 am

Re: extract column label/identifier from matrix

Postby vytama » Thu Dec 11, 2014 1:08 pm

Here it is:

!z=48
delete a
vector a
for !j = 1 to !z
vector aa
aa = !j
matrix ab = a
delete a
matrix(48) a=@vcat(ab,aa)
next
rowvector column_number=@transpose(a)

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: extract column label/identifier from matrix

Postby EViews Gareth » Thu Dec 11, 2014 2:17 pm

That's very confusing code.

What's the name of the underlying matrix containing the numbers, and what size is it?

vytama
Posts: 72
Joined: Wed Dec 19, 2012 11:05 am

Re: extract column label/identifier from matrix

Postby vytama » Thu Dec 11, 2014 2:35 pm

Yes, it is - I am sure there is a better way to do this but this was the best I could come up with. What I am trying to do is to place numbers 1 to 48 in this case and place them to rowvector/vector that I could add to the another existing matrix(let's call it matriz y) with 48 columns. Matrix a houses these numbers- and both matrix and y have 48 columns. But when I run this code, column starts with 0 instead of 1 and then matrix a has 49 columns. I hope thi explanation makes sense. Thanks.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: extract column label/identifier from matrix

Postby EViews Gareth » Thu Dec 11, 2014 2:42 pm

Code: Select all

!z = @cols(y) vector(!iz) a for !i=1 to !z a(!i)=!i next y = @vcat(a,y)

vytama
Posts: 72
Joined: Wed Dec 19, 2012 11:05 am

Re: extract column label/identifier from matrix

Postby vytama » Fri Dec 12, 2014 8:42 am

Thank you, it's perfect.


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 2 guests