Importing matrices from Matlab

For requesting general information about EViews, sharing your own tips and tricks, and information on EViews training or guides.

Moderators: EViews Gareth, EViews Moderator

pbuehr
Posts: 7
Joined: Wed Jul 22, 2015 8:10 am

Importing matrices from Matlab

Postby pbuehr » Wed Jul 22, 2015 8:21 am

Dear community,

First of all: I'm a total noob to eviews, so I excuse myself in advance for asking questions which have posted herein possibly the 1000th time already or seem to be quite daft...

I'd like to know how I can import a matrix created in matlab into eviews in order to use it for regressions. If you could subsequently explain how to define a discrete column of this matrix as a vector of independent variables for an OLS regression, that would be great...

Thanks for your help!

P.S. Any hint for an effective tutorial is highly welcome!!!

CharlieEVIEWS
Posts: 202
Joined: Tue Jul 17, 2012 9:47 am

Re: Importing matrices from Matlab

Postby CharlieEVIEWS » Wed Jul 22, 2015 8:29 am

1.) save it as a .txt or .csv from matlab
2.) create your workfile in eviews (be sure it has the correct structure and size)
3.) file --> import --> matrix from file
4.) if your variable of interest is the fourth column of your matrix X, do something like: myvariable=columnextract(X,4), mtos(myvariable,myvariable_series), and your new series called myvariable_series will be ready to into an equation.

Any more questions, just ask.

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: Importing matrices from Matlab

Postby startz » Wed Jul 22, 2015 9:20 am

Or, for the first step, use

Code: Select all

xrun
and

Code: Select all

xget
in EViews to directly import the matrix from Matlab.

CharlieEVIEWS
Posts: 202
Joined: Tue Jul 17, 2012 9:47 am

Re: Importing matrices from Matlab

Postby CharlieEVIEWS » Wed Jul 22, 2015 9:51 am

dont forget to xopen(type=m)!

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: Importing matrices from Matlab

Postby startz » Wed Jul 22, 2015 9:54 am

CharlieEVIEWS wrote:dont forget to xopen(type=m)!

Good point.

Also, EViews doesn't care about capitalization of variables but Matlab does. So watch out for that.

pbuehr
Posts: 7
Joined: Wed Jul 22, 2015 8:10 am

Re: Importing matrices from Matlab

Postby pbuehr » Thu Jul 23, 2015 1:02 am

Thanks for your help!

I will focus on the way directly linked to Matlab.
Now, how do I run my script within this strange Matlab Output window? It tried some things in the command line of xrun, however, he doesn't get it.

CharlieEVIEWS
Posts: 202
Joined: Tue Jul 17, 2012 9:47 am

Re: Importing matrices from Matlab

Postby CharlieEVIEWS » Thu Jul 23, 2015 5:01 am

Set your cd as usual:

xrun cd 'C:\<directory of your function>'

then just run the script as you would usually:

xrun <yourscriptname>

then after your script is finished running (you might want to look into the timeout options if the script is real big) you can use the xget function as described above by startz to bring your matrice into eviews, then use the columnextract and mtos as per my first reply.

pbuehr
Posts: 7
Joined: Wed Jul 22, 2015 8:10 am

Re: Importing matrices from Matlab

Postby pbuehr » Thu Jul 23, 2015 6:08 am

Next problem:

When I apply this command columnextract via "Generate", I get the following error message: Illegal lag or index specification for series COLUMNEXTRACT(<Name>).
I tried to open a new workspace because I thought it could be due to different number of observations of the several matrices, but that was not the cause. Could it be that the name of my matrix should not contain any specific signs or so...?

And what is this mtos command and the thing about series for?

Thanks in advance

CharlieEVIEWS
Posts: 202
Joined: Tue Jul 17, 2012 9:47 am

Re: Importing matrices from Matlab

Postby CharlieEVIEWS » Thu Jul 23, 2015 6:19 am

The generate tries to create a new series called columnextract(<name>) which is not what you want to be doing. You need to explicitly get the series out of the matrix first, unless it's a vector. Its possible you need to do something like: vector myvariable=columnextract(X,4), which builds a vector from the appropriate column, as you might expect. Once you've got your variable out of the matrix as a vector, you then need to turn it into a series (eviews uses series objects for estimations in equation objects). If it's already a vector in MATLAB, then you can go straight to turning it into a series using the mtos command.

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: Importing matrices from Matlab

Postby startz » Thu Jul 23, 2015 6:24 am

Alternatively, if you're more comfortable programming in Matlab, create a variable for each series you want in Matlab and then just xget them directly.

pbuehr
Posts: 7
Joined: Wed Jul 22, 2015 8:10 am

Re: Importing matrices from Matlab

Postby pbuehr » Thu Jul 23, 2015 7:10 am

Thanks again.

Yeah, I am definitely used to Matlab but I'd really like to know how to implement such minor things in eviews as I don't want to give up even more clarity in my Matlab scripts. Besides, I'm currently working with a very old version of Matlab. So, OLS regressions pose quite a problem without toolboxes and modern functions...

It still doesn't work, I'm sorry. So, how exactly do I have to type in the command, and where? I gave it a shot with all possible varieties in both command line at the top and in the generate windows, I always got an error message (and, unfortunately, never the same).

I already thought that error messages in Matlab are completely useless but this is hell! XD

CharlieEVIEWS
Posts: 202
Joined: Tue Jul 17, 2012 9:47 am

Re: Importing matrices from Matlab

Postby CharlieEVIEWS » Thu Jul 23, 2015 7:12 am

What error message do you get when you type

Code: Select all

vector myvariable=columnextract(X,4)


replacing X with your matrix, and 4 with the column which relates to your variable? I think the EViews error messages are much clearer than MATLAB to be honest, which are often impossibly cryptic.

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: Importing matrices from Matlab

Postby startz » Thu Jul 23, 2015 7:18 am

You type the commands either into the EViews command window or into an EViews program which you then run. Commands might look something like

Code: Select all

xrun "a=X(:,1);"
xrun "b=X(:,2);"
xget a
xget b


Alternatively, you might go back to a version of CharlieEViews original suggestion and write out a text file or Excel file in Matlab and then open that file in EViews.

pbuehr
Posts: 7
Joined: Wed Jul 22, 2015 8:10 am

Re: Importing matrices from Matlab

Postby pbuehr » Thu Jul 23, 2015 7:38 am

CharlieEVIEWS wrote:What error message do you get when you type

Code: Select all

vector myvariable=columnextract(X,4)


replacing X with your matrix, and 4 with the column which relates to your variable? I think the EViews error messages are much clearer than MATLAB to be honest, which are often impossibly cryptic.


I simply get: COLUMNEXTRACT is not defined

CharlieEVIEWS
Posts: 202
Joined: Tue Jul 17, 2012 9:47 am

Re: Importing matrices from Matlab

Postby CharlieEVIEWS » Thu Jul 23, 2015 7:40 am

whoops! @columnextract. Apologies :D


Return to “General Information and Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 17 guests