Help using Base SAS procedures

Regression excluding individual observations

Reply
N/A
Posts: 1

Regression excluding individual observations

Hello,

I am trying to run firm-year specific regressions in SAS to get to an expected value for industry-year. However, I need to exclude the i'th observation. For example, if there are 20 observations for 1995 for a specific industry (IND), the regression for obs 1 would be based on obs 2-20. The regression for obs 2 would be based on obs 1 and obs 3-20. I can't seem to find a way to exclude the variable individually. I found a reweight function that can exclude a specific observation by changing the weight to zero, but I would have to do that for every observation and run thousands of individual regressions. If I didn't need to exclude the i'th observation I know the code would be:

Proc Reg;
by fyear IND;
run;

Any ideas on how to exclude the observation? Thanks for the help.

BC
PROC Star
Posts: 7,474

Re: Regression excluding individual observations

As long as you have (or create) a variable that contains the obs number, you can simply exclude any particular obs with a where statement.

Art
> Hello,
>
> I am trying to run firm-year specific regressions in
> SAS to get to an expected value for industry-year.
> However, I need to exclude the i'th observation. For
> example, if there are 20 observations for 1995 for a
> specific industry (IND), the regression for obs 1
> would be based on obs 2-20. The regression for obs 2
> would be based on obs 1 and obs 3-20. I can't seem to
> find a way to exclude the variable individually. I
> found a reweight function that can exclude a specific
> observation by changing the weight to zero, but I
> would have to do that for every observation and run
> thousands of individual regressions. If I didn't need
> to exclude the i'th observation I know the code would
> be:
>
> Proc Reg;
> by fyear IND;
> run;
>
> Any ideas on how to exclude the observation? Thanks
> for the help.
>
> BC
Super User
Posts: 10,035

Re: Regression excluding individual observations

It looks like cross-verify test for cluster analysis.
You need to make a macro to process it iterative.
What does your original data look like?
I think it is not very difficulty task.


Ksharp
Valued Guide
Valued Guide
Posts: 684

Re: Regression excluding individual observations

Your question is related to the PRESS statistic (leave-one-out method) that is an option in REG. But I don't think there is an option to get a listing of the parameter estimates for each observation exclusion. Here is a quick macro that does what you want. It assume you are modeling y as a function of x. For this very simple macro, you must give the number of observations in the %do statement.Then, each observation is given, in turn, a weight of 0 (with 1 for the rest); the regression is done; the parameter estimates are stored (in parms); and then these estimates are stacked in a file called parms2. This is printed: there are two records for each observation (estimates of intercept and slope for each observation, when that observation is given a weight of 0). In this quick and dirty macro, the first record of parms2 has a missing value. You can delete. If you had four predictor variables, parms2 would have 5 records for each observation.

Right now, the individual regression output is suppressed. If you want to see the full results for each observation, comment out the ods listing statements at the start and end of the macro.

data a;
input x1 y;
id = _n_;
datalines;
0 2
1 4
2 3
3 6
4 6
5 5
6 8
7 10
8 9
9 9
;
run;

%macro jk;
ods listing exclude all;
data parms2;
%do i = 1 %to 10;
data b; set a;
if (id eq &i) then weight=0;
else weight=1;
run;
proc print data=b;run;
proc reg data=b ;
ods output parameterestimates=parms;
weight weight;
model y = x1;
run;
data parms2; set parms2 parms;
%end;
ods listing ;
proc print data=parms2;
%mend jk;

%jk;
run;
Super User
Posts: 10,035

Re: Regression excluding individual observations

Hello . LVM
It is impressed for me to see the code you post.
In general,I think you are seasoned statistician about general linear model especiall for mixed model.
But in the future, I hope I will become seasoned statistician just like you ,That is the thing after ten years. Smiley Happy


Ksharp
Ask a Question
Discussion stats
  • 4 replies
  • 752 views
  • 0 likes
  • 4 in conversation