Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Forming decile IVOL portfolios

    Hi all,

    For a reasearch topic i need to from decile portfolios based on montly date of the last 60 month (minimun 24 month) using the CRSP data base. I have so far written the following stata code using previous posts and topics. However, I am wondering if I am determining IVOL correctly as it seems to be a lot higher than observed in previous studies. In addition, I am failing to form monthly H-L (decile 10-decile 1) portfolios.

    I would like to hear your opinions on how best to approach this and whether I made any mistakes. Thanks in advance for you help!!

    * TS set the data
    egen firm = group(PERMNO)
    egen time = group(date)
    tsset firm time

    * Winsor returns
    winsor RET, gen(wret) p(0.05)
    drop RET
    rename wret RET

    * Merge with FF 3 factors
    gen Date = year(date)*100 + month(date)
    drop if Date < 196301
    drop if Date > 202312

    merge m:1 Date using "C:\Users\thoma\Desktop\MR.DRS. programma\Finance and investment\Scriptie\Data\FF 3_QMJ.dta"
    drop if Date < 196106
    drop if Date > 200412

    * Express returns in right decimals (only use when RET is the one needed)
    gen RET1 = (RET * 100)
    drop RET
    rename RET1 RET
    drop if RET == .
    drop if RET == 0

    * Generate excess return variable
    generate RET_EXC = RET- RF

    **IVOL based on FF3 using ASGEN
    sort firm time

    bys firm: asreg RET_EXC MktRF SMB HML, window(time 60) fit min(24)
    drop if missing(_Nobs)
    bys firm: asrol _residuals, gen (IVOL) stat(sd) wind(time 60) min(24)
    drop if missing(IVOL)

    * Create lag IVOL = IVOL t-1
    sort firm time
    gen lag_IVOL = L.IVOL
    drop if missing(lag_IVOL)

    *Creating 10 IVOL portfolios
    by time, sort: egen IVOL_decile = xtile(lag_IVOL), nq(10)

    *Value weighted decile return
    capture program drop one_weighted_return
    program define one_weighted_return
    egen numerator = total(mkt_cap*RET)
    egen denominator = total(mkt_cap)
    gen vw_mean_RET = numerator/denominator
    gen EXC_vw_mean_RET = vw_mean_RET - RF
    exit
    end

    runby one_weighted_return, by(time IVOL_decile)

    *Equally weighted decile return
    by time IVOL_decile, sort: egen ew_mean_RET = mean(RET)
    by time IVOL_decile, sort: gen EXC_ew_mean_RET = ew_mean_RET-RF



    input double PERMNO long date double PRC float mkt_cap double(vwretd ewretd) float(firm time) double(Date MktRF SMB HML RF) float QMJ byte _merge float(RET RET_EXC)
    25283 1126 35.875 333350.5 .05184823 .08914016 13296 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 2.5 2.25
    25267 1126 47 1262561 .05184823 .08914016 13294 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 8.045978 7.795978
    22410 1126 34.375 166443.75 .05184823 .08914016 11032 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 4.166667 3.916667
    13936 1126 20.5 30668 .05184823 .08914016 3605 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 5.128205 4.878205
    37815 1126 4 1596 .05184823 .08914016 15442 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 14.285715 14.035715
    37567 1126 -22.25 10390.75 .05184823 .08914016 15397 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 3.488372 3.238372
    10137 1126 51.375 479739.75 .05184823 .08914016 132 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 5.384615 5.134615
    31835 1126 -4.875 7834.125 .05184823 .08914016 14405 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 14.705883 14.455883
    20546 1126 22.125 18275.25 .05184823 .08914016 9340 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 14.193548 13.943548
    23819 1126 51.25 207408.75 .05184823 .08914016 12414 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 -1.4423077 -1.6923077
    13610 1126 35.875 463684.4 .05184823 .08914016 3312 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 15.261044 15.011044
    24483 1126 -23.25 21483 .05184823 .08914016 13001 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 6.896552 6.646552
    27772 1126 31.25 22593.75 .05184823 .08914016 13705 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 6.382979 6.132979
    13434 1126 15.375 100629.38 .05184823 .08914016 3187 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 4.2372885 3.9872885
    10532 1126 -12.625 5037.375 .05184823 .08914016 518 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 20.238096 19.988096
    34008 1126 -4.28125 10638.906 .05184823 .08914016 14780 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 7.03125 6.78125
    16053 1126 39.75 51277.5 .05184823 .08914016 5486 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 15.21739 14.96739
    31704 1126 9.75 5450.25 .05184823 .08914016 14382 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 25 24.75
    27609 1126 29.5 39500.5 .05184823 .08914016 13675 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 -2.0576131 -2.3076131
    17734 1126 -15.375 6027 .05184823 .08914016 6898 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 11.818182 11.568182
    18059 1126 29.25 96846.75 .05184823 .08914016 7206 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 10.377358 10.127358
    25806 1126 33.125 55915 .05184823 .08914016 13380 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 .3787879 .12878788
    25478 1126 14.75 58985.25 .05184823 .08914016 13326 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 16.831682 16.581682
    20933 1126 17.75 49433.75 .05184823 .08914016 9717 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 2.898551 2.648551
    29700 1126 3.75 2887.5 .05184823 .08914016 14037 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 -2.5 -2.75
    14357 1126 37.125 2247807.5 .05184823 .08914016 3983 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 -3.257329 -3.507329
    27342 1126 23.75 19950 .05184823 .08914016 13628 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 6.741573 6.491573
    11404 1126 86.375 1390119.3 .05184823 .08914016 1356 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 4.0298505 3.7798505
    19617 1126 10.625 70911.25 .05184823 .08914016 8564 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 1.1904762 .9404762
    20431 1126 59 211043 .05184823 .08914016 9263 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 -3.2786884 -3.5286884
    36388 1126 15.875 31194.375 .05184823 .08914016 15192 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 22.115383 21.865383
    36943 1126 12.25 6627.25 .05184823 .08914016 15289 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 19.512194 19.262194
    26569 1126 17 65960 .05184823 .08914016 13505 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 7.936508 7.686508
    29209 1126 2.125 913.75 .05184823 .08914016 13948 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 6.25 6
    23405 1126 36 373428 .05184823 .08914016 12013 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 3.5971224 3.3471224
    14795 1126 57.625 306968.38 .05184823 .08914016 4388 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 6.712963 6.462963
    14592 1126 76.5 610087.5 .05184823 .08914016 4196 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 1.3245033 1.0745033
    12976 1126 57.5 119255 .05184823 .08914016 2797 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 1.321586 1.0715859
    12650 1126 44.75 91200.5 .05184823 .08914016 2534 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 15.11254 14.86254
    20976 1126 23.625 76379.625 .05184823 .08914016 9759 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 21.935484 21.685484
    27705 1126 10.5 25326 .05184823 .08914016 13693 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 15.068494 14.818494
    33769 1126 1.125 3825 .05184823 .08914016 14738 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 -10 -10.25
    38092 1126 -11.75 4653 .05184823 .08914016 15489 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 23.68421 23.43421
    10727 1126 46.625 31751.625 .05184823 .08914016 704 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 9.705882 9.455882
    15579 1126 65.25 257607 .05184823 .08914016 5118 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 2.7559054 2.5059054
    38463 1126 6.75 2970 .05184823 .08914016 15551 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 22.727274 22.477274
    34227 1126 23.5 25309.5 .05184823 .08914016 14816 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 -3.836317 -4.086317
    13311 1126 45.5 613840.5 .05184823 .08914016 3084 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 5.202312 4.952312
    36783 1126 -31.625 38645.75 .05184823 .08914016 15263 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 2.016129 1.766129
    32117 1126 2.125 1096.5 .05184823 .08914016 14455 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 13.333334 13.083334
    26307 1126 39.25 51849.25 .05184823 .08914016 13464 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 1.7948717 1.5448717
    33910 1126 6.375 5023.5 .05184823 .08914016 14766 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 10.869565 10.619565
    28433 1126 15.375 87960.38 .05184823 .08914016 13819 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 16.261683 16.011683
    36679 1126 76 64068 .05184823 .08914016 15242 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 .6622517 .41225165
    11455 1126 63 793674 .05184823 .08914016 1405 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 6.105263 5.855263
    32002 1126 -3.1875 3060 .05184823 .08914016 14435 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 6.25 6
    35668 1126 -2.8125 7031.25 .05184823 .08914016 15065 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 18.421053 18.171053
    33435 1126 18.5 11359 .05184823 .08914016 14682 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 3.496503 3.246503
    32125 1126 9.25 17020 .05184823 .08914016 14457 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 9.999999 9.749999
    27975 1126 12.75 167280 .05184823 .08914016 13740 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 14.045376 13.795376
    36898 1126 22 17138 .05184823 .08914016 15282 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 10.691824 10.441824
    32870 1126 33.5 39865 .05184823 .08914016 14584 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 21.98198 21.73198
    35289 1126 33.875 48881.63 .05184823 .08914016 15000 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 17.316017 17.066017
    12511 1126 42 110964 .05184823 .08914016 2400 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 1.510574 1.260574
    29356 1126 13.375 18738.375 .05184823 .08914016 13974 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 3.883495 3.633495
    14752 1126 19.875 24943.125 .05184823 .08914016 4351 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 13.57143 13.32143
    36046 1126 4.125 21532.5 .05184823 .08914016 15134 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 9.548385 9.298385
    27043 1126 34.125 133804.13 .05184823 .08914016 13582 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 3.018868 2.768868
    37284 1126 -6.625 32641.375 .05184823 .08914016 15347 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 8.163265 7.913265
    35609 1126 24.5 13842.5 .05184823 .08914016 15057 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 2.0833335 1.8333335
    32184 1126 19.25 23196.25 .05184823 .08914016 14467 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 1.986755 1.736755
    24491 1126 27.875 143835 .05184823 .08914016 13009 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 6.559242 6.309242
    58149 1126 36.25 38860 .05184823 .08914016 18908 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 -3.388704 -3.638704
    12319 1126 48.5 98794.5 .05184823 .08914016 2237 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 12.463768 12.213768
    24328 1126 42.75 104951.25 .05184823 .08914016 12891 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 12.5 12.25
    12781 1126 31.25 113062.5 .05184823 .08914016 2645 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 12.107623 11.857623
    11375 1126 11 13640 .05184823 .08914016 1328 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 8.641975 8.391975
    38666 1126 10.125 14823 .05184823 .08914016 15584 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 2.5316455 2.2816455
    31341 1126 8.75 7122.5 .05184823 .08914016 14325 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 18.644068 18.394068
    10436 1126 13.875 18453.75 .05184823 .08914016 424 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 5.714286 5.464286
    10823 1126 39.25 199743.25 .05184823 .08914016 797 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 8.275862 8.025862
    18956 1126 45.5 336791 .05184823 .08914016 7965 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 6.744868 6.494868
    30816 1126 4.25 10306.25 .05184823 .08914016 14231 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 13.333334 13.083334
    14760 1126 14.125 141532.5 .05184823 .08914016 4359 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 -1.7391304 -1.9891304
    36193 1126 1.25 4336.25 .05184823 .08914016 15158 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 25 24.75
    27641 1126 11.125 13127.5 .05184823 .08914016 13683 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 12.658228 12.408228
    32029 1126 32.75 14049.75 .05184823 .08914016 14439 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 3.968254 3.718254
    38359 1126 9.125 9453.5 .05184823 .08914016 15531 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 7.352942 7.102942
    12810 1126 5.75 8688.25 .05184823 .08914016 2665 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 9.523809 9.273809
    36003 1126 -13.5625 12992.875 .05184823 .08914016 15128 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 -5.652174 -5.902174
    18542 1126 38.5 1049086.5 .05184823 .08914016 7635 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 3.67893 3.42893
    13557 1126 33.625 106793 .05184823 .08914016 3268 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 9.349593 9.099593
    12757 1126 17.25 40986 .05184823 .08914016 2623 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 6.153846 5.903846
    22664 1126 -9 4410 .05184823 .08914016 11283 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 9.090909 8.840909
    36601 1126 6.625 22034.75 .05184823 .08914016 15230 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 8.163265 7.913265
    10188 1126 15.625 29171.875 .05184823 .08914016 183 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 15.74074 15.49074
    33224 1126 3.5 3416 .05184823 .08914016 14644 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 3.7037036 3.4537036
    38076 1126 .625 6243.75 .05184823 .08914016 15486 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 25 24.75
    32547 1126 14.125 30156.875 .05184823 .08914016 14529 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 -10.31746 -10.56746
    19350 1126 58.375 402845.9 .05184823 .08914016 8307 37 196301 4.93 3.08 2.21 .25 -1.3947372 3 13.349515 13.099515
    end
Working...
X