BookmarkSubscribeRSS Feed
amanda_cz
Calcite | Level 5

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_IDyearpricebps
00120040.150.02
00120050.160.05
00120060.130.03
00120070.180.04
00120080.190.06
00220041.20.1
00220051.150.3
00220051.830.5
00820013.50.33
00820023.80.54
00820033.60.63
00820134.50.49
01120043.14
01120033.55
01120053.73.5
01120123.84.5
4 REPLIES 4
SteveDenham
Jade | Level 19

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

amanda_cz
Calcite | Level 5

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

SteveDenham
Jade | Level 19

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

amanda_cz
Calcite | Level 5

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 881 views
  • 0 likes
  • 2 in conversation