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
- /
- General Programming
- /
- number of observation in the regression outset

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

4 weeks ago

hello,

I am using a macro to conduct regression analysis using sas 9.4. the goal is to have results for every firm-year, here is the program:

%* run regression for each subsample by cusip and store estimation in a file with year identifier.;

proc reg data=one outest =two noprint ;

by cusip;

model dependent_var = independent1 independent2;

run;

data out_&fyear.;

set two;

fyear=&fyear.;

run;

**%mend**;

my question is how can I have the number of observation in the outest file (two)?

i used EDF command but it gives me the number of regressors in the model not the number of observations regressed.

thank you in advance

Accepted Solutions

Solution

4 weeks ago

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

4 weeks ago

Use this small example and drop the variables you dont want

```
proc sort data = sashelp.class;
by sex;
run;
proc reg data=sashelp.class noprint outest=est;
by sex;
model height=weight / sse;
run;
data est;
set est;
nObs = _P_ + _EDF_;
run;
```

All Replies

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

4 weeks ago

Just to be clear, you want a variable containing the number of pbservations used within each by group in the regression?

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

4 weeks ago

yes, this is what i want

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

4 weeks ago

You can do this by adding the variables _P_ and _EDF_ to the outest dataset. These are the number of parameters estimated, including the intercept and the error degrees of freedom, which when summed together gives the number of observations.

Solution

4 weeks ago

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

4 weeks ago

Use this small example and drop the variables you dont want

```
proc sort data = sashelp.class;
by sex;
run;
proc reg data=sashelp.class noprint outest=est;
by sex;
model height=weight / sse;
run;
data est;
set est;
nObs = _P_ + _EDF_;
run;
```

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

4 weeks ago

thank you for your response. my regression is a little bit more complicated that requires doing regression for each firm in each year.

the problem was in having the same error degrees of freedom every year, so i wanted a command that prints the number of observation explicitly so i can check my results.

i used this equation before and it worked.

i have just found that the problem is in some of the sample observations.

thank you again and have a nice day

the problem was in having the same error degrees of freedom every year, so i wanted a command that prints the number of observation explicitly so i can check my results.

i used this equation before and it worked.

i have just found that the problem is in some of the sample observations.

thank you again and have a nice day