Page 1 of 1
extract column label/identifier from matrix
Posted: Thu Dec 11, 2014 7:32 am
by vytama
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
Re: extract column label/identifier from matrix
Posted: Thu Dec 11, 2014 10:09 am
by EViews Gareth
I don't think you can. Perhaps add a row to the top of the matrix containing a column number?
Re: extract column label/identifier from matrix
Posted: Thu Dec 11, 2014 11:11 am
by vytama
thank you. What is the best way to do that?
Re: extract column label/identifier from matrix
Posted: Thu Dec 11, 2014 11:15 am
by EViews Gareth
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.
Re: extract column label/identifier from matrix
Posted: Thu Dec 11, 2014 12:30 pm
by vytama
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?
Re: extract column label/identifier from matrix
Posted: Thu Dec 11, 2014 12:32 pm
by EViews Gareth
Add 1?
Re: extract column label/identifier from matrix
Posted: Thu Dec 11, 2014 12:58 pm
by vytama
no, the vector jumps from 0 to 2,3, 4 etc. still keeps 0 in the first column and counts to 49 columns
Re: extract column label/identifier from matrix
Posted: Thu Dec 11, 2014 1:00 pm
by EViews Gareth
I'd need to see the full code to figure out what you're doing wrong.
Re: extract column label/identifier from matrix
Posted: Thu Dec 11, 2014 1:08 pm
by vytama
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)
Re: extract column label/identifier from matrix
Posted: Thu Dec 11, 2014 2:17 pm
by EViews Gareth
That's very confusing code.
What's the name of the underlying matrix containing the numbers, and what size is it?
Re: extract column label/identifier from matrix
Posted: Thu Dec 11, 2014 2:35 pm
by vytama
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.
Re: extract column label/identifier from matrix
Posted: Thu Dec 11, 2014 2:42 pm
by EViews Gareth
Code: Select all
!z = @cols(y)
vector(!iz) a
for !i=1 to !z
a(!i)=!i
next
y = @vcat(a,y)
Re: extract column label/identifier from matrix
Posted: Fri Dec 12, 2014 8:42 am
by vytama
Thank you, it's perfect.