## How to use rolling regression and calculate the skewness of residuals

Occasional Contributor
Posts: 7

# How to use rolling regression and calculate the skewness of residuals

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

Dennis

Posts: 2,655

## Re: How to use rolling regression and calculate the skewness of residuals

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

Occasional Contributor
Posts: 7

## Re: How to use rolling regression and calculate the skewness of residuals

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.

Dennis

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