Page 1 of 1

least square regression matrices

Posted: Thu Sep 03, 2015 9:43 am
by sakerstallda
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

Re: least square regression matrices

Posted: Thu Sep 03, 2015 9:57 am
by EViews Gareth
You cannot.

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

Re: least square regression matrices

Posted: Thu Sep 03, 2015 11:22 am
by CharlieEVIEWS
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.

Re: least square regression matrices

Posted: Thu Sep 03, 2015 11:22 pm
by sakerstallda
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

Re: least square regression matrices

Posted: Fri Sep 04, 2015 3:11 am
by trubador
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.