Hi, I am running a time series model with multiple firms with multiple years of observation (more than 10,000 observations). I want to get R-squares for individual firms. I know that r-square will show up in the individual firms' output report.But I don't know how to obtain a data file includes both firm_id and also R-square for individual firms. Any suggestion will be appreciated.
my basic code is
PROC AUTOREG DATA=TS;
by firm_id;
MODEL price=bps;
OUTPUT OUT=OUT1;
RUN;
Original data sample:
firm_ID | year | price | bps |
---|---|---|---|
001 | 2004 | 0.15 | 0.02 |
001 | 2005 | 0.16 | 0.05 |
001 | 2006 | 0.13 | 0.03 |
001 | 2007 | 0.18 | 0.04 |
001 | 2008 | 0.19 | 0.06 |
002 | 2004 | 1.2 | 0.1 |
002 | 2005 | 1.15 | 0.3 |
002 | 2005 | 1.83 | 0.5 |
008 | 2001 | 3.5 | 0.33 |
008 | 2002 | 3.8 | 0.54 |
008 | 2003 | 3.6 | 0.63 |
008 | 2013 | 4.5 | 0.49 |
011 | 2004 | 3.1 | 4 |
011 | 2003 | 3.5 | 5 |
011 | 2005 | 3.7 | 3.5 |
011 | 2012 | 3.8 | 4.5 |
Try using ODS to get a dataset with the R squared values:
PROC AUTOREG DATA=TS;
by firm_id;
MODEL price=bps;
OUTPUT OUT=OUT1;
ods output fitstatistics=fitstatistics;
RUN;
This will generate a dataset in your WORK library with the regression R squared values for each BY variable.
Steve Denham
Hi, I tried to use this method. However, sas gives me an warning message and there seems to be an error in the code.
WARNING: Output 'fitstatistics' was not created. Make sure that the output object name,
label, or path is spelled correctly. Also, verify that the appropriate procedure
options are used to produce the requested output object. For example, verify that
the NOPRINT option is not used.
NOTE: The data set WORK.OUT1 has 6240 observations and 11 variables.
NOTE: PROCEDURE AUTOREG used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds
Since I was able to make this work by looping the example in the PROC AUTOREG documentation, I will guess that the ODS file name may be different in whatever version of SAS/ETS you are using. In order to check this out, wrap your proc autoreg block in ODS TRACE ON and ODS TRACE OFF and check the log for the table names.
Here is my example:
title1 'Lack of Fit Study';
title2 'Fitting White Noise Plus Autoregressive Errors to a Sine Wave';
data a;
pi=3.14159;
do grp = 1 to 3;
do time = 1 to 75;
if time > 75 then y = .;
else y = sin( pi * ( time / 50 ) );
x = ranuni( 1234567 );
output;
end;
end;
run;
ods trace on;
proc autoreg data=a plots;
by grp;
model y = x ;
output out=b p=pred pm=xbeta;
ods output fitsummary=fitsummary;
run;
ods trace off;
Steve Denham
Message was edited by: Steve Denham
Thanks so much for your help.
I switched from
ods output fitstatistics=fitstatistics;
to
ods output fitsummary=fitsummary;
Now it works.
Thanks si much for your help! I am grateful for it.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.