Programming the statistical procedures from SAS

Proc reg with year dummies

Reply
Occasional Contributor
Posts: 5

Proc reg with year dummies

[ Edited ]

I am trying to run a regression that has year dummy variables in the equation, and have two questions regarding it.

 

First question is to do with how to include more than 30 year dummies in PROC REG.

 

Currently, I have created year dummies using the following code.

data X;

set X;

array yrdummy(*) dy&startyr - dy&endyr;

do i=1 to dim(yrdummy);

if fyear = i+&startyr then yrdummy{i} = 1;

else yrdummy{i} = 0;

end;

run;

 

Now, I am only test-running regression with 5 years (&startyr=2011 and &endyr=2015),

but I will eventually run with more than 30 years of data. 

How do I efficiently add these created dummy variables in my regression? 

 

Second question is to do with regression outcome.

 

When I run regression, I usually write the following code. 

 

proc reg data=x outest=x1 noprint;

model y=x1 x2; *here I need to include yr dummies after x2;

run;

 

Now, the outcome I need is the coefficients on x1 and x2, not the coefficients on yr dummies, and adj R-squared and number of observations. But when I use 'outest', I can't find R-square or number of observations. Do I have to use other means for my output or is there a way to have coefficients, R2, n and other STATA-like information (SSR, SSE, SST etc)?

 

 

 

 

Trusted Advisor
Posts: 1,131

Re: Proc reg with year dummies

I believe your array is fine, it should work even if you are having more than 30 years as you are using the macro variable for the start and end year.

 

About the coefficients, and adj R-squared and number of observations. Please try to use th odes trace on and off as i used and in the log you get something as displayed.

 

then in order to get the data into datasets try

 

ods output parameterestimates=parameterestimates nobs=nobs ;

proc reg data=sashelp.class outest=x;
model age=height weight;
run;

ods output close;

 

the ods output statement will help you get the expected dataset.

 

image.png

Thanks,
Jag
Super User
Posts: 17,963

Re: Proc reg with year dummies

If you can use PROC GLM instead you can add the year variable as a CLASS variable and not have to create dummy variables. 

Occasional Contributor
Posts: 5

Re: Proc reg with year dummies

Can you please write SAS commands to run proc glm without year dummy?

I have y(dependent var) and x1, x2, ..., x3 and year that has year figures. Thank you in advance.

 

Super User
Posts: 17,963

Re: Proc reg with year dummies


kelSAS wrote:

Can you please write SAS commands to run proc glm without year dummy?

I have y(dependent var) and x1, x2, ..., x3 and year that has year figures. Thank you in advance.

 



http://www.lexjansen.com/mwsug/1999/paper15.pdf

http://www2.sas.com/proceedings/sugi22/STATS/PAPER267.PDF

 

 

There are a lot of examples online. Note that there still are year dummy variables, you just don't have to code/create them. You may also want to review the parameterization methods for creating dummy variables and how to specify that in SAS. The default is GLM coding while you probably want referential coding, even if you're not using that estimate. 

 

 

Ask a Question
Discussion stats
  • 4 replies
  • 209 views
  • 0 likes
  • 3 in conversation