BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vl12
Calcite | Level 5

thanks again. However the code won't work for me as it's only for one company ibm and has an exact beginning and ending dates. My sample companies have different beginning and ending dates.

 

PG's code works just that I need to back fill the missing quarter with previous quarter. If this can be solved in his original code, that would solve my problem.

 

Thank you so much for trying to help!

PGStats
Opal | Level 21

If all you want is a regression of the previous 8 obs, then the dates don't matter and the code is a bit different:

 

/* Create periods of 8 previous observations */
data long;
do obs = 1 by 1 until(last.gvKey);
    set sasforum.erctest;
    by gvkey notsorted;
    do grp = obs+1 to obs+8;
        if grp > 8 then output;
        end;
    end;
run;

proc sort data=long; by gvkey grp; run;

/* Fit regressions. Keep only full groups (8 obs) in the results */
proc reg data=long rsquare noprint 
    outest=longEst(
        where=(_P_ + _EDF_= 8)
        keep= _P_  _EDF_ gvKey grp intercept ue _RSQ_);
where cmiss(car, ue) = 0;
by gvkey grp;
model car = ue / selection=none;
run;

proc sql;
create table regStats as
select distinct
    b.gvKey,
    b.datadate,
    a.intercept,
    a.ue as slope,
    a._RSQ_
from 
    longEst as a inner join
    long as b on a.gvKey=b.gvKey and a.grp=b.obs
order by gvKey, datadate;
quit;
PG
vl12
Calcite | Level 5

Hi PG,

 

yes. This would work. This code restrict the regression to be run on each gvkey datadate pair to 8 observations,which is what I ask for.

 

If I'd like to use all the observations in prior quarters but require at least 8 obs for a given gvkey and datadate,  how can I do it? So some regression will have 8 obs, some will have 9 or more. And can you output the number of obs used in the regression as well?

 

Thank you so much!

PGStats
Opal | Level 21

You seem to want a cumulative regression now. That's a different matter. It might be better to put it as a new question to attact more attention.

PG
vl12
Calcite | Level 5

thanks. will make a new post

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 19 replies
  • 1701 views
  • 2 likes
  • 3 in conversation