___  ____  ____  ____  ____ tm
 /__    /   ____/   /   ____/
___/   /   /___/   /   /___/   10.1   Copyright 1984-2009
  Statistics/Data Analysis            StataCorp
                                      4905 Lakeway Drive
     Special Edition                  College Station, Texas 77845 USA
                                      800-STATA-PC        http://www.stata.com
                                      979-696-4600        stata@stata.com
                                      979-696-4601 (fax)

Single-user Stata for Macintosh perpetual license:
       Serial number:  6410544727
         Licensed to:  Christopher Baum
                       Boston College

Notes:
      1.  (-m# option or -set memory-) 10.00 MB allocated to data
      2.  (-v# option or -set maxvar-) 5000 maximum variables
      3.  Command line editing disabled
      4.  Stata running in batch mode

. do calcRAIM 

. * calcRAIM  1.0.8  18sep2005  cfb
. * per Bandopadhyaya and Jones, "How do they feel", prelim. version, p.7
. * 1.0.0: 24apr2005 initial implementation
. * 1.0.1: 27apr2005 relax assumption of balanced panel
. * 1.0.2: 04may2005 add table header, text file output
. * 1.0.3: 17jun2005 deal with gaps in firm history within window
. * 1.0.4: 19jun2005 refinement of code for gaps
. * 1.0.5: 23jun2005 further refinement of gap handling
. * 1.0.6: 26jun2005 further refinement of gap handling
. * 1.0.7: 04jul2005 handle gaps with tsfill
. * 1.0.8: 18sep2005 add logic for raim_d (daily) file
. 
. // 7C15: must merge historical values of MISI into current content, patch gap
> s
. 
. set more off

. 
. // 9204 fix memory, matsize settings
. set mem 100m

Current memory allocation
-------------------------

                    current                                 memory usage
    settable          value     description                 (1M = 1024k)
    --------------------------------------------------------------------
    set maxvar         5000     max. variables allowed           1.751M
    set memory          100M    max. data space                100.000M
    set matsize         400     max. RHS vars in models          1.254M
                                                            -----------
                                                               103.006M

. set matsize 1000

Current memory allocation
-------------------------

                    current                                 memory usage
    settable          value     description                 (1M = 1024k)
    --------------------------------------------------------------------
    set maxvar         5000     max. variables allowed           1.751M
    set memory          100M    max. data space                100.000M
    set matsize        1000     max. RHS vars in models          7.713M
                                                            -----------
                                                               109.465M

. cd "/fmwww0/repec/raim/MassInd/"
/fmwww0/RePEc/RAIM/MassInd

. use bloomberg_BBMXAll, clear

. 
. * calc five-day sd of daily returns; maxwin should be set to twice window wid
> th
. local win 5

. 
. tsfill, full

. mvsumm pctchg, gen(movsd) stat(sd) window(`win') end

. 
. * get range of dates available
. su qq, meanonly

. local max = r(max)

. // 7C15: prevent conditional from aborting
. if `max' < `win' {
.         di as err "Inadequate data"
.         g int nfirms = .
.         g pvalue = .
. //      error 9
.         }

. else {
. * housekeeping
. qui {
. * for each available date, calculate rank correlation
. * between moving sd and returns and save results
. forv i=`win'/`max' {
  2.         qui {
  3.         spearman pctchg movsd if qq == `i'
  4.         replace RAIM = 100.0 * r(rho) if qq == `i' & fobs
  5.         replace pvalue = r(p) if qq == `i' & fobs
  6.         replace nfirms = r(N) if qq == `i' & fobs
  7. * take account of quote date referring to following day
.         replace quotedate = qd-1 if qq == `i' & fobs 
  8.         }