turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Regression excluding individual observations

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-23-2011 02:22 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to bcRam

05-23-2011 05:49 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to bcRam

05-24-2011 01:05 AM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ksharp

05-24-2011 09:53 AM

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;

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-24-2011 08:42 PM

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.

Ksharp

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.

Ksharp