Page 1 of 2

Importing matrices from Matlab

Posted: Wed Jul 22, 2015 8:21 am
by pbuehr
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!!!

Re: Importing matrices from Matlab

Posted: Wed Jul 22, 2015 8:29 am
by CharlieEVIEWS
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.

Re: Importing matrices from Matlab

Posted: Wed Jul 22, 2015 9:20 am
by startz
Or, for the first step, use

Code: Select all

xrun
and

Code: Select all

xget
in EViews to directly import the matrix from Matlab.

Re: Importing matrices from Matlab

Posted: Wed Jul 22, 2015 9:51 am
by CharlieEVIEWS
dont forget to xopen(type=m)!

Re: Importing matrices from Matlab

Posted: Wed Jul 22, 2015 9:54 am
by startz
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.

Re: Importing matrices from Matlab

Posted: Thu Jul 23, 2015 1:02 am
by pbuehr
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.

Re: Importing matrices from Matlab

Posted: Thu Jul 23, 2015 5:01 am
by CharlieEVIEWS
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.

Re: Importing matrices from Matlab

Posted: Thu Jul 23, 2015 6:08 am
by pbuehr
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

Re: Importing matrices from Matlab

Posted: Thu Jul 23, 2015 6:19 am
by CharlieEVIEWS
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.

Re: Importing matrices from Matlab

Posted: Thu Jul 23, 2015 6:24 am
by startz
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.

Re: Importing matrices from Matlab

Posted: Thu Jul 23, 2015 7:10 am
by pbuehr
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

Re: Importing matrices from Matlab

Posted: Thu Jul 23, 2015 7:12 am
by CharlieEVIEWS
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.

Re: Importing matrices from Matlab

Posted: Thu Jul 23, 2015 7:18 am
by startz
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.

Re: Importing matrices from Matlab

Posted: Thu Jul 23, 2015 7:38 am
by pbuehr
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

Re: Importing matrices from Matlab

Posted: Thu Jul 23, 2015 7:40 am
by CharlieEVIEWS
whoops! @columnextract. Apologies :D