least square regression matrices

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

sakerstallda
Posts: 7
Joined: Thu Aug 27, 2015 5:17 am

least square regression matrices

Postby sakerstallda » Thu Sep 03, 2015 9:43 am

Hello!
Is it possible to do a least square regression with matrices in eviews? I tried as below with yieldstat and loptidsak being matrices but did not get it to work. What is the best way to do?

equation eq1.ls yieldstat c loptidsak

Best regards

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

Re: least square regression matrices

Postby EViews Gareth » Thu Sep 03, 2015 9:57 am

You cannot.

Either convert the matrices to series/groups (mtos function), or calculate the coefficients manually using matrix algebra.

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

Re: least square regression matrices

Postby CharlieEVIEWS » Thu Sep 03, 2015 11:22 am

A third, more tedious option would be to xput <matrix> into matlab/R and xrun an ols.m (from the lesage toolbox or otherwise). However, this requires you have a valid matlab license if opening a matlab connection, and then you still would have to bring the objects you wanted back into eviews.

sakerstallda
Posts: 7
Joined: Thu Aug 27, 2015 5:17 am

Re: least square regression matrices

Postby sakerstallda » Thu Sep 03, 2015 11:22 pm

Thank you.
I have realised that everything I want to do would be easier in Matlab, but unfortunately I do not have a license.

Actually, what I want to do is to perform a simple regression with two vectors (not matrices) and to save the slope coeffecient and intercept in another vector. Can I use "ls" for vectors, or it has to be series? How do I convert vectors back to series? How do I save the slope and intercept in a vector?

I would really appreciate your help!

Best regards

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: least square regression matrices

Postby trubador » Fri Sep 04, 2015 3:11 am

I think you can use the Optimize feature in EViews:

Code: Select all

'Generate some artificial data wfcreate u 100 series x1 = nrnd series x2 = nrnd series y = 5 + 3*x1 + 2*x2 + nrnd/2 group xgr.add 1 x1 x2 stom(xgr,xmat) stom(y,yvec) 'OLS analysis with matrices vector(3) coefvec = 1 vector(100) resvec scalar minsq optimize(min=1,finalh=hessmat) olsmat(resvec,coefvec, yvec, xmat) scalar sig = @sqrt(@sum(resvec)/(@obs(resvec)-@rows(coefvec))) vector stdvec = @sqrt(@getmaindiagonal(2*sig^2*@inverse(hessmat))) subroutine olsmat(vector res,vector betas,vector yvar,matrix xvar) res = yvar-xvar*betas res = @epow(res,2) endsub
Estimated parameters and their standard errors are stored in vector coefvec and stdvec, respectively.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest