Importing matrices from Matlab
Moderators: EViews Gareth, EViews Moderator
Importing matrices from Matlab
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!!!
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!!!
-
- Posts: 202
- Joined: Tue Jul 17, 2012 9:47 am
Re: Importing matrices from Matlab
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.
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.
-
- Non-normality and collinearity are NOT problems!
- Posts: 3775
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Importing matrices from Matlab
Or, for the first step, use and in EViews to directly import the matrix from Matlab.
Code: Select all
xrun
Code: Select all
xget
-
- Posts: 202
- Joined: Tue Jul 17, 2012 9:47 am
Re: Importing matrices from Matlab
dont forget to xopen(type=m)!
-
- Non-normality and collinearity are NOT problems!
- Posts: 3775
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Importing matrices from Matlab
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.
Re: Importing matrices from Matlab
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.
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.
-
- Posts: 202
- Joined: Tue Jul 17, 2012 9:47 am
Re: Importing matrices from Matlab
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.
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
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
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
-
- Posts: 202
- Joined: Tue Jul 17, 2012 9:47 am
Re: Importing matrices from Matlab
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.
-
- Non-normality and collinearity are NOT problems!
- Posts: 3775
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Importing matrices from Matlab
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
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
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
-
- Posts: 202
- Joined: Tue Jul 17, 2012 9:47 am
Re: Importing matrices from Matlab
What error message do you get when you type
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.
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.
-
- Non-normality and collinearity are NOT problems!
- Posts: 3775
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Importing matrices from Matlab
You type the commands either into the EViews command window or into an EViews program which you then run. Commands might look something like
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.
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
CharlieEVIEWS wrote:What error message do you get when you typeCode: 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
-
- Posts: 202
- Joined: Tue Jul 17, 2012 9:47 am
Re: Importing matrices from Matlab
whoops! @columnextract. Apologies
Return to “General Information and Tips and Tricks”
Who is online
Users browsing this forum: No registered users and 17 guests