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.
reshaping a matrix
Moderators: EViews Gareth, EViews Moderator
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: reshaping a matrix
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
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
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.
Code: Select all
matrix newmat = @transpose(@unvec(@vec(@transpose(oldmat)), new_n_cols))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.
Re: reshaping a matrix
Thank you so much.
It worked perfectly.
Regards.
It worked perfectly.
Regards.
Who is online
Users browsing this forum: No registered users and 2 guests
