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-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
  • 2 replies
  • 2956 views
  • 0 likes
  • 2 in conversation