Portfolios by Size (CIZ format) - 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                         */
/* Update    : November 2024 to reflect CRSP CIZ data format                         */                     
/* Author    : Michael Boldin, Luis Palacios, Mark Keintz, WRDS                      */
/* Note      : Uses ODS to make a PDF fle comparing results to CRSP Portfolio data   */
/* ********************************************************************************* */
 libname crsp ('/wrds/crsp/sasdata/a_indexes_v2','/wrds/crsp/sasdata/a_stock_v2', '/wrds/crsp/sasdata/a_ccm/') ;
 
/* 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=MthCalDt permno MthRet year_prev size_lag)
     MSF_DEC_V (keep=MthCalDt permno     year      size )
      / view=MSF_DEC_V ;
 
  set crsp.msf_v2;
  by permno;
 
  where MthCalDt >= '01dec1999'd;
  where also not missing(MthPrc) and not missing(shrout) and not missing(MthRet);
 
  year=year(MthCalDt);
 
  /* 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*MthPrc;
  if month(MthCalDt)=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+MthRet);
 
  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 MthCalDt;
run;
 
/* PROC means will make value-weighted mean monthly returns, output to VWRETS  */
 
proc means data = MSF_GROUPS noprint;
  by decile MthCalDt;
  var MthRet / 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 NYSE/NYSE American/Nasdaq Market Capitalization Decile 1-10 Returns.   */
/* INDNO 1000482 - Decile 1 ~~ INDNO 1000491 - Decile 10                       */

data crspind;
set crsp.indMthSeriesData_ind;
where 1000482<=indno<=1000491;
keep indno MthCalDt MthTotRet decile;
decile = indno - 1000481;
run;

PROC SORT DATA = CRSPIND; BY MTHCALDT DECILE; RUN;
 
/* Join CRSP Index decile returns with our calculated returns, for comparison        */
proc sql;
  create table DECILE_RETURNS
  as select r.*, i.mthTotRet
  from VWRETS as r  
  left join 
  crspind as i
  on r.mthcaldt=i.mthcaldt 
  and r.decile=i.decile
  order by decile, mthcaldt;
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"
        mthtotret="Returns"
        MthCalDt='  ';
  format MthCalDt yymmd7. ;
 
  plot mthtotret*mthcaldt=1 vwret*mthcaldt=2 / vref=0 overlay legend=legend1 ;
run;
   
ods pdf close;
   
/* ********************************************************************************* */
/* *************  Material Copyright Wharton Research Data Services  *************** */
/* ****************************** All Rights Reserved ****************************** */
/* ********************************************************************************* */

Top of Section

Top