Page 1 of 1

Deleting a column from a matrix (and a row from a vector)

Posted: Mon May 06, 2013 5:54 am
by wags
Hi,

I am estimating G regressions and storing a scalar from each regression in a row vector and a computed data series (nobs x 1) in each column of a matrix. Upon completion, I have a (Gx1) row vector and a (nobs X G) matrix. Later in the program, I multiply the (matrix * row vector). No problem.

For a few iterations, the computed series cannot be calculated so the column that is placed in the matrix has NAs. Needless to say, the computation of the (matrix * row vector) fails when this happens.

Is there a way that I could: (a) check for NAs in the (nobs x G) matrix when all of the iterations are completed and (b) delete the corresponding columns in the matrix and rows in the row vector for which NAs appear?

Thanks for your help.

Re: Deleting a column from a matrix (and a row from a vector

Posted: Mon May 06, 2013 7:46 am
by EViews Gareth
Not easy to do either.

Perhaps the best way to check for NAs is to check that each column has the same number of observations. You can use @cobs to do that. If you know how many observations should be in each column, you could just check whether the mimimum of @cobs is equal to the proper number.


In EViews 8 the best way to delete rows/columns from a matrix is to use the @droprow data member of a matrix.

Re: Deleting a column from a matrix (and a row from a vector

Posted: Mon May 06, 2013 12:36 pm
by wags
Thanks. I'll play around with your suggested approach.

Would this alternative approach be feasible?

Will EViews allow you to expand a matrix dynamically? For instance, I could create and initial column vector (of 0's or something) and then concatenate a new column if that column does not contain NAs. This would yield a final matrix of only numerical values.

Re: Deleting a column from a matrix (and a row from a vector

Posted: Mon May 06, 2013 12:36 pm
by wags
Thanks. I'll play around with your suggested approach.

Would this alternative approach be feasible?

Will EViews allow you to expand a matrix dynamically? For instance, I could create and initial column vector (of 0's or something) and then concatenate a new column if that column does not contain NAs. This would yield a final matrix of only numerical values.

Re: Deleting a column from a matrix (and a row from a vector

Posted: Mon May 06, 2013 12:45 pm
by EViews Gareth
There's a @hcat function that will concatenate.