extract column label/identifier from matrix
Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason
extract column label/identifier from matrix
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
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
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
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
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
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
I'd need to see the full code to figure out what you're doing wrong.
Re: extract column label/identifier from matrix
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)
!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
That's very confusing code.
What's the name of the underlying matrix containing the numbers, and what size is it?
What's the name of the underlying matrix containing the numbers, and what size is it?
Re: extract column label/identifier from matrix
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
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
Thank you, it's perfect.
Who is online
Users browsing this forum: No registered users and 2 guests
