next up previous
Next: Robust standard errors Up: Statistics Previous: Statistics

Weighted means with negative weights

I often want to calculate the return to portfolios of stocks where the weights of some stocks are negative. For instance, suppose we have a dataset PORTWEIGHTS that contains

permno, portweight
10001, 0.2
10006, 0.3
10010, -0.4

We want to calculate the returns to this portfolio over January 2001.

So we say:

data msf;
   set crsp.msf(keep=permno date ret);
   where intnx('month', date, 1)-1 = '31Jan2001'd); *Moves date to end-of-month;

and then merge this with PORTWEIGHTS by PERMNO to get a dataset PORTWEIGHTSRETS, and then just say

proc means data=portweightsrets;
var ret/weight=portweight;

The problem is that SAS sets negative weights to zero when it calculates means. So permno 10010, for instance, will not be included in the portfolio.

The straightforward way to handle this is to say:

data portweights;
  set portweights;
  if portweight<0 then modifiedret=-ret;

proc means data=portweightsrets;
  var modifiedret/weight=absportweight;

Andre de Souza 2012-11-19