reshaping a matrix

For technical questions regarding estimation of single equations, systems, VARs, Factor analysis and State Space Models in EViews. General econometric questions and advice should go in the Econometric Discussions forum.

Moderators: EViews Gareth, EViews Moderator

facosta
Posts: 23
Joined: Wed Jul 07, 2010 9:16 am

reshaping a matrix

Postby facosta » Fri Jan 14, 2011 6:16 am

Hello there. Thank you guys for all the help in the forum.
I am programming in Eviews and I would like to know if there is any way to reshape a matrix by a single command. For example, in GAUSS programming, you use: "reshape(name_of_ the_ old_matrix, new_n°_rows, new_n°_cols)".
Can you use a smmilar code to do this in Eviews 7?
Thank you!
Best regards.

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

Re: reshaping a matrix

Postby EViews Gareth » Fri Jan 14, 2011 9:03 am

Unfortunately not. Possibly the easiest thing to do is to vec it, and then unvec it.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: reshaping a matrix

Postby EViews Glenn » Fri Jan 14, 2011 1:05 pm

Gareth is correct that we don't have a built-in, and he is right about @unvec, but I think he undersells the existing tools somewhat since we can feed the output from one matrix function into another. Thus, the EViews command

Code: Select all

matrix newmat = @transpose(@unvec(@vec(@transpose(oldmat)), new_n_cols))
should be the equivalent of the Gauss reshape command. The @vec converts the original matrix into a vector and the @unvec converts back into a matrix. I've verified this with a couple of examples from the Gauss manual, but you should double-check with a few others. The reason it is a bit more complicated than it otherwise might be is that Gauss stores matrices in row-major order so we have to work in transpose space.

I should note that unlike Gauss, the code above will not repeat observations to fill in larger matrices. For that, you should use some variant of the .fill command to get the original matrix to have the right total number of elements.

facosta
Posts: 23
Joined: Wed Jul 07, 2010 9:16 am

Re: reshaping a matrix

Postby facosta » Mon Jan 17, 2011 6:07 am

Thank you so much.
It worked perfectly.
Regards.


Return to “Estimation”

Who is online

Users browsing this forum: No registered users and 2 guests