Solved
Contributor
Posts: 38

# how to obtain the regression coefficients for variables for EACH OBSERVATION

I want to obtain the coefficients, T value, R square, intercept, and residual for EACH OBS through regression and then output/outest the result into a new dataset.

For example, there are 10 obs in a sample and there are 2 independent variables (X1 and X2). I want to generate a dataset like below:

obs

1     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

2     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

3     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

4     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

5     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

6     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

7     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

8    coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

9     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

10     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

Please be noted what I want is not the set of parameter estimates, t value, adjusted R square etc for the WHOLE sample.

What I know is to obtain the residual for each obs (through below code) and output into a new dataset, but how to write the code for obtaining the other iterms? Thank you.

proc reg data=dataset;

model y = x1 x2;

output out=dataset_reg

r=residual;

run;

quit;

Accepted Solutions
Solution
‎05-08-2014 10:57 AM
Posts: 5,543

## Re: how to obtain the regression coefficients for variables for EACH OBSERVATION

Posted in reply to comeon2012

No, Maybe it is just a question of vocabulary but in my mind, a statistical model is a way to summarize and sometimes understand a phenomenon underlying data with a smaller amount of information. I don't understand the purpose of getting one model per data point, as you seem to want.

PG

PG

All Replies
Posts: 5,543

## Re: how to obtain the regression coefficients for variables for EACH OBSERVATION

Posted in reply to comeon2012

I don't know about the concept of observation r-square, but for the rest, you could do:

proc reg data=sashelp.class outest=oe;

model weight = height age;

output out=op predicted=predicted residual=residual student=tValue;

run;

quit;

proc sql;

create table want as

select op.*,

oe.height*op.height as heightCoef,

oe.age*op.age as ageCoef,

oe.intercept

from oe, op;

select * from want;

quit;

PG

PG
Contributor
Posts: 38

## Re: how to obtain the regression coefficients for variables for EACH OBSERVATION

Hi PG,

Thank you for your help. It goes well but the intercept keeps the same for all obs. Is it possible to get the intercept for EACH obs?

Thanks.

Solution
‎05-08-2014 10:57 AM
Posts: 5,543

## Re: how to obtain the regression coefficients for variables for EACH OBSERVATION

Posted in reply to comeon2012

No, Maybe it is just a question of vocabulary but in my mind, a statistical model is a way to summarize and sometimes understand a phenomenon underlying data with a smaller amount of information. I don't understand the purpose of getting one model per data point, as you seem to want.

PG

PG
Contributor
Posts: 38

## Re: how to obtain the regression coefficients for variables for EACH OBSERVATION

I double checked the paper I followed and realised that I misunderstood its methodology.

Yes, my question doesn't make sense. Thank you anyways.

Super User
Posts: 23,776

## Re: how to obtain the regression coefficients for variables for EACH OBSERVATION

Posted in reply to comeon2012

Your question doesn't make sense.

That would mean a regression model for each observation, which isn't statistically valid.

Or are you looking for the values of X1, X2 instead of the coefficients?

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 5 replies
• 365 views
• 5 likes
• 3 in conversation