Asked by Marcin Kuc
on 1 Aug 2011

Hi,

I would like to perform a simple econometric regression using Matlab, but I have been struggling to do it for a few days now. Quite simply, I have a set of data for both X and Y. I would like to perform a regression of the following form: Y= BetaZero + Beta*X + ErrorTerm. Could anyone please tell me what is the right function to do so? I've been trying to accomplish that by using regress(), but I realised that it does not return the value of the constant term (aka Beta zero or alpha). Thank you very much for your help.

Answer by Oleg Komarov
on 1 Aug 2011

Accepted answer

Use regstats then with the same inputs:

regstats(y,x,'linear')

Marcin Kuc
on 1 Aug 2011

Betas = [ones(length(X),1) X] \ y

Shashank Prasanna
on 12 Jan 2013

Answer by Fangjun Jiang
on 1 Aug 2011

You have the right function. Just try it with three return variables.

[B,BINT,R] = REGRESS(Y,X) returns a vector R of residuals.

Read the full text of help regress

Marcin Kuc
on 1 Aug 2011

Oleg Komarov
on 1 Aug 2011

You have to add a column of ones for the constant. As already suggested read the documentation.

Marcin Kuc
on 1 Aug 2011

However, I would be very grateful if you could tell me exact way of getting the constant. Thank you in advance.

Answer by Fangjun Jiang
on 2 Aug 2011

To use regress();

%% x=(1:100)'; y=10+2*x+rand(100,1);

[B,BINT,ErrorTerm]=regress(y,[ones(size(x)),x]); BetaZero=B(1) Beta=B(2)

BetaZero =

10.6381

Beta =

1.9976

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments