number of observation in the regression outset

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

number of observation in the regression outset

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
‎07-27-2017 10:58 AM
PROC Star
Posts: 746

Re: number of observation in the regression outset

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;

View solution in original post


All Replies
PROC Star
Posts: 746

Re: number of observation in the regression outset

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

Occasional Contributor
Posts: 6

Re: number of observation in the regression outset

yes, this is what i want
PROC Star
Posts: 746

Re: number of observation in the regression outset

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
‎07-27-2017 10:58 AM
PROC Star
Posts: 746

Re: number of observation in the regression outset

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;
Occasional Contributor
Posts: 6

Re: number of observation in the regression outset

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 Smiley Happy and have a nice day



☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 144 views
  • 1 like
  • 2 in conversation