BookmarkSubscribeRSS Feed
DennisLe
Calcite | Level 5

Hi there,

I'm trying to modify a rolling regression macro to calculate the idiosyncratic skewness of stocks. Basically it is the skewness of residuals after the regression.

However, I am not very sure how to change the code and export out the skewness to match each permno. The data used is CRSP so it's quite inconvenient to post here.

My macro for rolling regression can be found here and it is quite easy to use: (though right now it cannot be used to calculate the skewness)

www.nesug.org/proceedings/nesug07/sa/sa04.pdf


I am able to calculate the skewness for each stock individually using the code below:


  proc reg data=ABC noprint;

   by permno;

   model exret=mktrf smb umd hml;

   output out=_residues r=r;

  quit;

  proc univariate data=_residues;

  by permno;

  var r;

  output out=_iskewness mean=mu skewness=iskew;

quit;

However, this code is hard to add into the macro because im not sure how to match the output above with the respective permno.

I attach the macro here for easy reference. Thanks in advance for any idea Smiley Happy

Dennis

2 REPLIES 2
SteveDenham
Jade | Level 19

Hi Dennis,

I would think that the variable permno would be included on the dataset _iskewness, due to the BY statement (see OUTPUT statment documentation for PROC UNIVARIATE).  You have &by_id defined in your macro, but I couldn't find permno.  If the two are referring to the same thing, then just substitute &by_id into the above code.

I hope I'm not completely misinterpreting what you are trying to do here.

Steve Denham

DennisLe
Calcite | Level 5

Hi Steve,

Thanks for your reply. I actually figured out one way to do it by just mergeing  _outest_ds with _iskewness. This step simply adds iskewness to the _outest_ds

The program is like:

  proc reg data=ABC noprint outest=_outest_ds;

   by permno;

   model exret=mktrf smb umd hml;

   output out=_residues r=r;

  quit;

  proc univariate data=_residues;

  by permno;

  var r;

  output out=_iskewness mean=mu skewness=iskew;

quit

data _outest_ds; merge _outest_ds _iskewness; run;

I tested the answer alr so this works.

The program is very useful to calculate idiosyncratic skewness.

Smiley Happy

Dennis

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3228 views
  • 0 likes
  • 2 in conversation