Portfolios by Size - Macro

Size Portfolios for all CRSP Securities

Example

/* ********************************************************************************* */
/* ************** W R D S   R E S E A R C H   A P P L I C A T I O N S ************** */
/* ********************************************************************************* */
/* Summary   : Size Portfolios for all CRSP Securities                               */
/* Date      : October 2004 Revised March and September 2011                         */
/* Author    : MIchael Boldin, Luis Palacios, Mark Keintz, WRDS                      */
/* Note      : Uses ODS to make a PDF fle comparing results to CRSP Portfolio data   */ 
/* ********************************************************************************* */

/* Step 1. Get CRSP monthly stocks for decile formation ------------- */
  
/* Make two data sets:                                                */
/*   MSF_DEC_V (A data VIEW): December SIZEs for establishing deciles */
/*   MSFX_LS   (A data FILE): All Monthly records with SIZELAG var.   */

data MSF_LS    (keep=date permno ret year_prev size_lag)
     MSF_DEC_V (keep=date permno     year      size )
      / view=MSF_DEC_V ;

  set crsp.msf; 
  by permno;

  where date >= '01dec1999'd;
  where also not missing(prc) and not missing(shrout) and not missing(ret);

  year=year(date); 

  /* Calculate Monthly Size.   Note: when there are no trades, CRSP stores  */
  /* -1*(bid/ask average) in PRC variable, so use ABS(prc) instead of prc,  */

  size = shrout*abs(prc);
  if month(date)=12 then output MSF_DEC_V;

  /* Get lag of Size.  At each PERMNO start, no lag available, so estimate  */
  size_lag = lag(size);
  if first.permno then size_lag=size/(1+ret); 

  year_prev = year - 1;  ** For matching to YEAR of the preceding December **;
  output MSF_LS;  
run;

/* Step 2. Compute Deciles for each year, using proc RANK  ---------------- */
/*   Sort December data so PROC RANK gets each year as consecutive records. */
proc sort data=MSF_DEC_V out=MSF_DEC; 
  by year;
run;

/* PROC RANK assigns SIZE groups (0 thru 9) for each recorod in each Dec.   */
proc rank data=MSF_DEC out=GROUPINGS group=10;
  by year; 
  var size;           /* The variable to be grouped             */
  ranks size_group;   /* The variable to hold group assignments */
run;  
  
  
/* Step 3. Assign Size Group to All months, save as MSF_GROUPS --------------- */
  
/* Here, for each monthly record in a given permno, previous DECEMBER group for*/
/* that permno is assigned.  I.e. all monthly 2001 records (which will have    */
/* YEAR_PREV=2000 in MSF_LS) will get assignments from December 2000 GROUPINGS */
/* records (YEAR=2000 in GROUPINGS).  Also since SIZE_GROUP is scored 0 thru 9 */
/* add 1, so decile will be 1 through 10 for presentation purposes.            */
  
proc sql; 
  create table MSF_GROUPS 
  as select m.* , g.size_group+1 as decile
  from MSF_LS as m     left join    groupings as g
    on  (m.permno=g.permno and m.year_prev=g.year )
    where size_group^=. 
	;
quit;  


/* Step 4. Compute Size Weighted Averages & Final Results -------------------- */
  
/* Sort all permno's for each DECILE*DATE in sequence, prepare for PROC MEANS  */
  
proc sort data=MSF_GROUPS; 
  by decile date; 
run;

/* PROC means will make value-weighted mean monthly returns, output to VWRETS  */

proc means data = MSF_GROUPS noprint;
  by decile date; 
  var ret / weight=size_lag ;/* Weight the return variable by SIZE_LAG         */
  output out = VWRETS        /* Dataset name for results                       */
    mean= vwret ;            /* VWRET is name of mean value-weighted return    */
run;
 
/* Step 5. Check results. Join & Compare to the CRSP MSIX Size Decile Returns. */
  
/* Get MSIX (CRSP Monthly Stock Index), & transpose 10 decile variables into   */
/* ten records, for DECILES 1 through 10.  The MSIX deciles are based on       */
/* portfolios by size (rebalanced each December).                              */

data msix1 (keep=caldt decile decret) ;
  set crsp.msix;
  array drate decret1-decret10;
  do decile=1 to 10;
    decret=drate{decile};
    output;
  end;
  label decret = 'Monthly Return for this Size Decile';
run;

/* Join MSIX decile returns with our calculated returns, for comparison        */
proc sql; 
  create table DECILE_RETURNS 
  as select r.*, i.decret 
  from VWRETS as r  left join   msix1 as i 
  on r.date=i.caldt and r.decile=i.decile
  order by decile, date;
quit; 

options device=pdfc;           /* Use PDF Color for graphic output report  */
ods pdf file='./portsize.pdf'; /* Turn on PDF output and name the PDF file */
ods listing close;             /* Turn off usual SAS listing output        */

/* Set up symbols and legends for upcoming GPLOT procedures */  
symbol1 interpol=join ci=green co=green value=diamond h=1 w=3 ;
symbol2 interpol=join ci=blue  co=blue  value=star    h=1 w=3; 

legend1 label=NONE  mode=SHARE across=1
  position=(top center inside)
  value=(h=1.5 justify=left "CRSP Index Size Decile Returns" 
         justify=left "Calculated Size Decile Returns-Value Weighted");

/* Make the Plots, which will be printed to the pdf file    */
proc gplot data=DECILE_RETURNS;  
  Title 'Compare Monthly Returns with CRSP Portfolio Returns'; 
  by decile; 
  label decile="Size Decile"
        decret="Returns"
        date='	';
  format date yymmd7. ;

  plot decret*date=1 vwret*date=2 / vref=0 overlay legend=legend1 ;
run; 
  
ods pdf close; 
  
/* ********************************************************************************* */
/* *************  Material Copyright Wharton Research Data Services  *************** */
/* ****************************** All Rights Reserved ****************************** */
/* ********************************************************************************* */

Top of Section

Top