Announcement

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

  • Regression on decile portfolios

    The below data example are the monthly returns of decile portfolios. In actual data file there are ten portfolio of each equal and value weighted schemes. The actual data sent comprises of equal weighted deciles from ew_mean__mom_d1_rt to ew_mean__mom_d10_rt and same number of value weighted deciles prefixed by vw instead of ew. The following is to be estimated on this data set:

    1. mean returns of each decile with corresponding t-stat. (This will be done by regressing each series of deciles on a constant only)
    2. CAPM alpha: This is regression intercept with corresponding t-stat of each decile (both equal and value included) on the market variable.
    3. Sharpe Ratio: This metrics for each decile is equal to decile return minus rf divided by the standard deviation of decile return minus rf.
    4. Treynors Ratio: This metrics for each decile is equal to decile return minus rf divided by the slope (beta) obtained from CAPM regression of No 2.

    The data example is listed below:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(vw_mean__mom_d10_rt ew_mean__mom_d10_rt vw_mean__mom_d1_rt ew_mean__mom_d1_rt vw_mean__mom_d2_rt ew_mean__mom_d2_rt market rf)
       -.18127036   -.18065533   -.08514345    -.0800608   -.09270895  -.10873426  -.07947595   .04609929
        .09685031     .0886065     .0814631    .09375563   .004813017  .015112385  .017945716 -.033898305
         .0603438    .05903351    .04477973    .02489921    .21591607    .1954424   .06002853  -.04210526
       .019839354     .0188993    .05498792    .04263351    .05901659   .05913275   .03831548   .04395605
       -.02682297  -.018050069   .010311595    .01431822  -.030677287  -.03331868  .004542337   .05263158
       -.02008798  -.017151017   -.03470596  -.031387527   -.05527843  -.05079902   .01344811  -.04333333
        .11195397      .162732    .02077459   .020806793    .08813529   .08500178   .06229282  .027874565
       -.04774369  -.035675764   -.05029603   -.06633819   -.02698591  -.03020655  -.06997918           0
        -.0966222   -.11258647  -.036162198   -.05091617   -.13442072  -.16520546  -.07618963 -.006779661
        .08526099    .08327052   .025536055     .1028324  -.006968618   .01753186   .06813693  .006825939
       -.09733598    -.0891442  -.068324044   -.11060635   -.04232053  -.04754167   -.0199876  .010169492
       -.04602319   -.04562232    .03602574   .028250476   .018392839   .03937935   .02877731  .006711409
      -.016974008    .04997362    .10014502    .11892826    .10398831   .10945087   .03131876           0
        .01247118   .029368175    .04045125   .016575322    .09754877   .10180693   .01104095           0
       -.02726269   -.01506107   -.02568028    -.0544266 -.0041998373 -.004975333  .034211498 -.006666667
        .04726009   .032158934    .09680207    .07769803    -.0885512  -.08820714  .014358676           0
       -.18697123    -.1511859   -.13047728   -.21020225   -.09764506  -.07879527  -.08321752           0
        .05156699    .11509594    .09820627    .08205896    .05328023   .10563334  .032028638           0
       -.08330358   -.08010757   -.03755666   -.04935039    .04223869   .03295358   .04721431           0
        .04705516   -.02862311  -.063173555    -.0571359   -.03518483 -.024408514  -.01979799           0
       -.01430397    .03700394    .13840449     .1581095     .0962168   .09204572    .0498063    .4214765
        .03688778    .03757279   -.08442055   -.07779593  -.028928613 -.027524896   .02058153   .02407932
       .007164881  .0036569794   -.10843354   -.12503271    -.1693249   -.1104847  -.01704484  -.02558783
       -.12754862   -.07295224    .09124506    .08992703    .14480525   .13898833   .00948285   .08161817
    -.00026872972  -.001225311   -.04028637  .0008293055  -.017147226 -.026370805  .031739596 -.026902886
         .1614271    .16308595   -.02777755   -.02680419   -.02069283  -.02048073    .0768103           0
        .05298949    .04851398   -.06444407   -.04389359    -.1218005   -.1110427  .030276556   .04045853
         .0517098     .0599384   .002772418    .01334573    .06506653   .07782368   .01883833  -.04406999
       .001956699  .0044480264   -.12324735   -.12435738   -.10702118   -.0777455   .00686522  .034124292
        .02986792    .02926191    .04829855   .030140774   -.09616727  -.14144461  -.04926972 -.007648601
       -.12263422   -.11714558   -.16301657   -.18657595    -.1640944   -.1453543  -.04327128  -.08125963
       -.17134134    -.1655021    .04599492    .12754366   .014097651   .04042576  -.09007718    .6253595
       -.11962546   -.11292293   -.13615431   -.10230471    -.0885328  -.08671775  .028864697  -.05589146
         .1539801    .15481937    .13356139    .13771035  -.020782905  -.02079319   .04505141   .03436426
       -.10801302   -.10980497   -.03024075   -.02351704   -.04400298  -.05643333  -.05635355  -.02461492
      -.011252048  -.011717683   .010400638   .016287094   -.04159468  -.04083998  .004167802  .019662486
          .083533     .0239561    .04022396    .05589216   -.09578046   -.0944159   .03382637  .062860616
        .06409612   .063811116     .1060375    .06071552    .06107508   .06100501   .04559198 -.025714286
        .04543072    .04401763    .04213051     .0300624  -.017212095 -.018200967  .032046095    -.186217
       .002351849    .04667261    .08302593   .066938475  -.034643363 -.024228863   .01507252   .14414415
      -.025111975   -.04666393   .023681413   .027011147    .08515178   .06265687  .011107094  -.03937008
        .03814507   .032935858   -.05552803    -.0549529    .00535803 -.002929761 -.003132465   .04098361
        .05346817    .06418588    .03992831    .04583146     .1222126   .11836734   .04309041 -.031496063
        .06304926    .06399554   -.03914729   -.04200653   .005157054   .05240205   .00944427 -.024390245
       -.13705194   -.13701284   -.01691731   -.02152171   .012711823   .02517817  .000140163          .1
        .06449163    .04508878   -.02356984  -.033513993  -.035538904 -.032465756  -.00934876 -.015151515
        .04700472    .04508416   -.02404215   -.02328768   .022761855 .0039785895  .011855665   -.1076923
       -.04775285   -.06784903   -.02508948 -.0016848495    .01522672  .021816265  .014963426    .0775862
       -.06443257    -.0645624   .018297255   .015561117     .0545591   .05643406  .011947694        -.08
       .072491966    .04129574  -.024315767  -.032825567    .07660355   .05779029   .03041744   .04347826
       -.06561126    -.0745742  -.011594357  -.015696263  .0020946702  .008637853   .01254612 -.016666668
       -.10813058   -.11592896   -.18991713    -.1990159    -.0431746  -.04324661  -.07832503 -.033898305
       .009259097   .020756625    .06167299   .024211174    .09679842   .12451657   .02555039   .01754386
       -.13399455    -.1651807   -.10117479   -.09720217   -.11391003  -.11497279  -.05860769    .0287931
       -.02961138   -.05838878   -.25201032   -.26684028   -.24397786   -.2470839  -.02201944    .0390481
       -.03357066   -.02111499   -.03773315  -.029786853   -.26759425  -.17819406  -.06099285   .04435484
        -.0850701    -.0850242   -.08169895   -.06420714     .0310008   .09612674  -.06335359  .003861004
         .0847838     .0841052    .07073693    .03392403    .20548715    .2426355   .05475259  .015384615
        .00744296    .15182397    -.2498121   -.24205716    .17421056    .0379025 -.001957272           0
      .0080328705 -.0019188467  -.011339888  -.070540465   .016144788  -.04501671    .0329588   .04545455
      -.007046435   -.00560515   -.11002719   -.07796963    .00619691 .0021486627  .004822546  -.16666667
         .2232764    .11174738    .15393427     .2380135    .12785694    .1345716   .03375831    .1652174
         .0452868    .11752037     .1890585    .17405723    .10799403   .11241113  .015596442 -.005522388
        .07533263    .08246953     .3164574      .320403   .020806944   .03825931 -.001401338  -.13702537
       -.03919758   -.04413805   -.10441796    -.0729718   -.09871516   -.1137645 -.008620298   .04052174
        .06712909    .05488251    .02990801    .05340606    .14464203   .14485054   .04581738   .04462644
        .09122027    .09489667    .28565454     .2553083    .09811682   .22822624   .03973568     -.00272
       -.06904627   -.08235581   .036592104    .06613888   .034956098   .03040757  .032609344  -.10957805
     -.0010226615    .05596735   -.04488378   -.05164978  -.017602434 -.015999822 -.003950925   .07513513
        .06591474    .07430313    .07666447      .066182 -.0022166944 -.005087604   .01076275   .01893749
       -.03654728  -.013483796   -.06920492   -.05080765   -.04490763  -.02913994  -.05046159  .022532895
        .05432805    .02129159  -.007824223 -.0001135127   .026768256  .028928647  .028705105 -.034904294
      -.021210345   -.04434619     .0400013    .08290202    .03439759  .012775147 -.000492759         -.1
        .04593057    .05355465   .036070883   .035338785    .04121177   .05911014   .01748928           0
        .06402377    .09074234   .017035993   .018673256  -.006892527 -.008528514   .03367931  -.00462963
     -.0008634874  -.017124832   .012288786   .016581304   .022670185  .011694073   .02104664 -.009302326
       -.16025718   -.17407355    .01861758   .002882909    .04437076  .032403354  .009295903   .02967136
        .06491467    .08848898   .018101824   .019244917    .07545424   .10509348  .015956363  .012219588
        .13717386    .14299387   -.05481096   -.06764241   -.02974429  -.02817233  .001926339  -.02702703
       .010593375    .01315797    .03796482   .035461027   .012470516   .01780226  .003958267 -.012407407
       .027143093   .018283656   -.14655557   -.14019935   -.07493122  -.09178464   .00627381  -.14682168
        .07843146     .0827109    .12697332    .11007153   -.03775569 -.022146804  .017782183   .06593407
      -.033498652   -.03803785   -.07761273   -.05089051  -.019360857  -.05240043 -.008931396  .010309278
       -.03444993  -.033050265     .0118049 -.0041329064   -.01334389   -.0077434   .06779242  .015306122
        .08982436    .07796862     .3503772     .3321544    .24415623    .2405888   .03933193  -.19095477
       -.04498287   -.05017506   .019882595   .031571873   -.03690799 -.030078683 -.001273156   .08074534
       -.07062563  -.034556508   -.15291037    -.1608362   -.05569534  -.05905105   -.0618791   .04597701
       -.04108484   -.04448353   -.08472862   -.10555337   -.04252707    -.099456 -.031409003   .06043956
        .16362718    .15840815  -.030529147   -.04783507    -.0758194   -.0479073 -.001836653    .0880829
       -.01520417   -.04935718   -.05556374   .008469924   .014872017  -.02781137  -.03080926 -.023809524
        .14825472    .16980487   .009420735    .04342137    .06823432   .02074468   .02365827   .08292683
       -.13042435   -.13187778 -.0002611185   .009433928   -.03952984 -.030094165   .01381636   -.0899099
       .014201035   .009493854    .01301928  -.005932443   -.12060607   -.1172693 -.006963575   .23401307
       .025688456   .013366709   -.11582106    -.1292953   -.01813987  -.01705804  -.02424476 -.033852078
        .09906305      .077659   .030445484    .02187163     .0752309  .005413346   .03849168  -.02457655
        .14727205    .12196179    .03881901   -.03446994 -.0026500665  .018915534  .022849614   .04613551
        .06038489    .05570481    .12844995     .2915827    .15274623   .19047496   .05464041  .011879577
       -.03801994    -.0511527    .02901731    .07733157   -.02142374 -.004599522  -.01371811  -.04310067
       -.08521917   -.04588118   -.01253918   -.04215752    .02731782   .05687196  .003942049   .01697479
       -.11821023   -.11270754 -.0020688411    .00558737   -.05361249   -.0581445 -.002071498 -.016691456
    end

  • #2
    I don't fully understand the instructions. For 1, 3, and 4, are the statistics calculated separately for ew and for vw, but for 2, a single statistic is calculated for the entire decile using both the ew and vw values?

    Comment


    • #3
      For all these, 1 - 4, the given statistics is to be calculated for ew and vw separately. If don't understand still, please rephrase the #2.

      Comment


      • #4
        Code:
        gen `c(obs_t)' obs_no = _n
        reshape long vw_mean__mom_d@_rt ew_mean__mom_d@_rt, i(obs_no) j(decile)
        reshape long @_mean__mom_d_rt, i(obs_no decile) j(weight) string
        rename _mean__mom_d_rt rt
        
        capture program drop one_weighted_decile
        program define one_weighted_decile
            regress rt
            gen mean_rt = _b[_cons]
            gen t_stat = mean_rt/_se[_cons]
            regress rt market
            gen capm_alpha = _b[_cons]
            gen capm_tstat = capm_alpha/_se[_cons]
            gen capm_beta = _b[market]
            gen delta = rt - rf
            summ delta
            gen sharpe_ratio = r(mean)/r(sd)
            gen treynors_ratio = r(mean)/capm_beta
            keep decile weight mean_rt t_stat capm_alpha capm_tstat sharpe_ratio treynors_ratio
            keep in 1
        end
        
        runby one_weighted_decile, by(decile weight) status

        Comment


        • #5
          The following error is faced when i run the code #4 on actual dataset:

          runby one_weighted_decile, by(decile weight) status

          elapsed ----------- by-groups ---------- ------- observations ------ time
          time count errors no-data processed saved remaining
          ------------------------------------------------------------------------------------
          00:00:01 1 1 0 108 0 00:00:28
          00:00:02 20 20 0 2,160 0 00:00:00

          --------------------------------------
          Number of by-groups = 20
          by-groups with errors = 20
          by-groups with no data = 0
          Observations processed = 2,160
          Observations saved = 0
          --------------------------------------

          .
          end of do-file

          Comment


          • #6
            It worked fine with the example data. Please post back with another example that exhibits the problem and I will troubleshoot.

            Comment


            • #7
              Ok. here is the new data example that encounters the problem:

              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input float(vw_mean__mom_d10_rt ew_mean__mom_d10_rt vw_mean__mom_d1_rt ew_mean__mom_d1_rt vw_mean__mom_d2_rt ew_mean__mom_d2_rt vw_mean__mom_d3_rt ew_mean__mom_d3_rt vw_mean__mom_d4_rt ew_mean__mom_d4_rt mkt rf)
                 -.18127036   -.18065533   -.08514345    -.0800608   -.09270895  -.10873426   -.10379143   -.09106496   -.15903504   -.14503379  -.07947595   .04609929
                  .09685031     .0886065     .0814631    .09375563   .004813017  .015112385     .0947659    .09002246    .07441291   .063575394  .017945716 -.033898305
                   .0603438    .05903351    .04477973    .02489921    .21591607    .1954424    .06657742    .06547141    .12431133    .10459058   .06002853  -.04210526
                 .019839354     .0188993    .05498792    .04263351    .05901659   .05913275    .06337429     .0435291  -.016448142  -.010577653   .03831548   .04395605
                 -.02682297  -.018050069   .010311595    .01431822  -.030677287  -.03331868 -.0007131266   -.00944411    -.0253488  -.024490613  .004542337   .05263158
                 -.02008798  -.017151017   -.03470596  -.031387527   -.05527843  -.05079902  -.002572402  -.003243702    .03726176    .04309453   .01344811  -.04333333
                  .11195397      .162732    .02077459   .020806793    .08813529   .08500178   -.04503968   -.03980085   -.05834927  -.037072286   .06229282  .027874565
                 -.04774369  -.035675764   -.05029603   -.06633819   -.02698591  -.03020655   -.04820964   -.05132149   -.05476396   -.05260365  -.06997918           0
                  -.0966222   -.11258647  -.036162198   -.05091617   -.13442072  -.16520546   -.11829288   -.11260398    -.1156188    -.1158127  -.07618963 -.006779661
                  .08526099    .08327052   .025536055     .1028324  -.006968618   .01753186     .1138469    .13518675    .04115018    .04984201   .06813693  .006825939
                 -.09733598    -.0891442  -.068324044   -.11060635   -.04232053  -.04754167    -.0950007   -.07397981   -.12301038   -.11300501   -.0199876  .010169492
                 -.04602319   -.04562232    .03602574   .028250476   .018392839   .03937935    .02984274    .06049855  -.026775025  -.003687734   .02877731  .006711409
                -.016974008    .04997362    .10014502    .11892826    .10398831   .10945087  -.021047805  -.021315293   .018526362   .008152018   .03131876           0
                  .01247118   .029368175    .04045125   .016575322    .09754877   .10180693   .022633856   .036754735   .031520233    .03906025   .01104095           0
                 -.02726269   -.01506107   -.02568028    -.0544266 -.0041998373 -.004975333   .002470354    .00528746  -.010524977   .005598936  .034211498 -.006666667
                  .04726009   .032158934    .09680207    .07769803    -.0885512  -.08820714    .12931989    .02328998   -.11691187   -.11396113  .014358676           0
                 -.18697123    -.1511859   -.13047728   -.21020225   -.09764506  -.07879527   -.09350917   -.08311508   -.08389197   -.07628806  -.08321752           0
                  .05156699    .11509594    .09820627    .08205896    .05328023   .10563334   .025772063    .04116239   .022851355    .02068152  .032028638           0
                 -.08330358   -.08010757   -.03755666   -.04935039    .04223869   .03295358    .06054921   .067520514    .10973819    .11088438   .04721431           0
                  .04705516   -.02862311  -.063173555    -.0571359   -.03518483 -.024408514   .005694113   .005120022    -.0292516   -.02845903  -.01979799           0
                 -.01430397    .03700394    .13840449     .1581095     .0962168   .09204572    .03787727    .04201932   .026467174   .015269396    .0498063    .4214765
                  .03688778    .03757279   -.08442055   -.07779593  -.028928613 -.027524896    .04681043   .073364705    .01865508   .005752974   .02058153   .02407932
                 .007164881  .0036569794   -.10843354   -.12503271    -.1693249   -.1104847 -.0027960865   -.03540596    .05440292    .02064101  -.01704484  -.02558783
                 -.12754862   -.07295224    .09124506    .08992703    .14480525   .13898833   .026758654   .033028927    .06789788   .071826465   .00948285   .08161817
              -.00026872972  -.001225311   -.04028637  .0008293055  -.017147226 -.026370805   .064934544    .07911448    .04297544    .02264481  .031739596 -.026902886
                   .1614271    .16308595   -.02777755   -.02680419   -.02069283  -.02048073   .029990926    .02050519   .068613455   .010857664    .0768103           0
                  .05298949    .04851398   -.06444407   -.04389359    -.1218005   -.1110427  -.007217906 -.0023872375   -.03333794   .006147426  .030276556   .04045853
                   .0517098     .0599384   .002772418    .01334573    .06506653   .07782368 -.0021062708  -.006066324   -.03875652 -.0006709695   .01883833  -.04406999
                 .001956699  .0044480264   -.12324735   -.12435738   -.10702118   -.0777455  -.023522547   -.07530624   -.04498753  -.037146214   .00686522  .034124292
                  .02986792    .02926191    .04829855   .030140774   -.09616727  -.14144461   -.07022837   -.10197812  -.023686424  -.033875145  -.04926972 -.007648601
                 -.12263422   -.11714558   -.16301657   -.18657595    -.1640944   -.1453543   -.12463928    -.1833557   -.10300412  -.010468494  -.04327128  -.08125963
                 -.17134134    -.1655021    .04599492    .12754366   .014097651   .04042576   -.17646258   -.11467083   -.09663752    .03587951  -.09007718    .6253595
                 -.11962546   -.11292293   -.13615431   -.10230471    -.0885328  -.08671775   -.07069156   -.05464563   -.07563876   -.07602469  .028864697  -.05589146
                   .1539801    .15481937    .13356139    .13771035  -.020782905  -.02079319    .09652696    .09885604    .14015187    .14352503   .04505141   .03436426
                 -.10801302   -.10980497   -.03024075   -.02351704   -.04400298  -.05643333   -.11501778   -.11974884   -.06316573   -.07071662  -.05635355  -.02461492
                -.011252048  -.011717683   .010400638   .016287094   -.04159468  -.04083998    .06655698    .06622626  -.019213764   -.06368443  .004167802  .019662486
                    .083533     .0239561    .04022396    .05589216   -.09578046   -.0944159   -.05970686   -.07224424    .05752414    .06133186   .03382637  .062860616
                  .06409612   .063811116     .1060375    .06071552    .06107508   .06100501    .12873349    .11251084    .03886002   .031279895   .04559198 -.025714286
                  .04543072    .04401763    .04213051     .0300624  -.017212095 -.018200967     .0621038    .07828704     .0825013    .08042611  .032046095    -.186217
                 .002351849    .04667261    .08302593   .066938475  -.034643363 -.024228863    -.0254337    -.0234925    .13265434    .13955803   .01507252   .14414415
                -.025111975   -.04666393   .023681413   .027011147    .08515178   .06265687    .01978307    .02688441    -.0475921  -.037108477  .011107094  -.03937008
                  .03814507   .032935858   -.05552803    -.0549529    .00535803 -.002929761   -.04731287   -.05110731  -.004533696   -.04822136 -.003132465   .04098361
                  .05346817    .06418588    .03992831    .04583146     .1222126   .11836734    .06778781    .04886597    .10172476     .1076104   .04309041 -.031496063
                  .06304926    .06399554   -.03914729   -.04200653   .005157054   .05240205  -.014103447  -.021391455   -.03059107  -.032927092   .00944427 -.024390245
                 -.13705194   -.13701284   -.01691731   -.02152171   .012711823   .02517817   -.06609972   -.07334001     .0849702    .08466126  .000140163          .1
                  .06449163    .04508878   -.02356984  -.033513993  -.035538904 -.032465756  -.010654514   -.04531504   -.04456202   -.05136401  -.00934876 -.015151515
                  .04700472    .04508416   -.02404215   -.02328768   .022761855 .0039785895  -.019599793   -.03817188  -.010407746   -.01846765  .011855665   -.1076923
                 -.04775285   -.06784903   -.02508948 -.0016848495    .01522672  .021816265   .007274326  .0034318245  -.022204787   -.03786679  .014963426    .0775862
                 -.06443257    -.0645624   .018297255   .015561117     .0545591   .05643406   .018757874   -.04069917   -.05081179   -.05120333  .011947694        -.08
                 .072491966    .04129574  -.024315767  -.032825567    .07660355   .05779029   -.02258455  -.019623324  -.009388788    .02482058   .03041744   .04347826
                 -.06561126    -.0745742  -.011594357  -.015696263  .0020946702  .008637853   -.03256722  -.065647826    .07763562    .03348743   .01254612 -.016666668
                 -.10813058   -.11592896   -.18991713    -.1990159    -.0431746  -.04324661   -.11500812    -.0879622   -.05743188   -.06016463  -.07832503 -.033898305
                 .009259097   .020756625    .06167299   .024211174    .09679842   .12451657  -.018444803   -.01566312   .034918047   .036088258   .02555039   .01754386
                 -.13399455    -.1651807   -.10117479   -.09720217   -.11391003  -.11497279   -.05125878   -.05617507   -.13392042   -.13480818  -.05860769    .0287931
                 -.02961138   -.05838878   -.25201032   -.26684028   -.24397786   -.2470839   -.09762415   -.10524087   -.19730794   -.23324046  -.02201944    .0390481
                 -.03357066   -.02111499   -.03773315  -.029786853   -.26759425  -.17819406   -.14838612    -.1707348    -.1389523    -.1482993  -.06099285   .04435484
                  -.0850701    -.0850242   -.08169895   -.06420714     .0310008   .09612674   -.03683351   -.03795326   -.10910247   -.11103055  -.06335359  .003861004
                   .0847838     .0841052    .07073693    .03392403    .20548715    .2426355    .23743697    .25801617    .24000508     .2228451   .05475259  .015384615
                  .00744296    .15182397    -.2498121   -.24205716    .17421056    .0379025   -.06851154   -.03753438  -.018752957   -.02775168 -.001957272           0
                .0080328705 -.0019188467  -.011339888  -.070540465   .016144788  -.04501671   -.03481493  -.032752577     .1596802    .09785473    .0329588   .04545455
                -.007046435   -.00560515   -.11002719   -.07796963    .00619691 .0021486627  -.031906594   -.04599451    .28006822    .27857202  .004822546  -.16666667
                   .2232764    .11174738    .15393427     .2380135    .12785694    .1345716   .008683017    .05465341    .08140881     .0872601   .03375831    .1652174
                   .0452868    .11752037     .1890585    .17405723    .10799403   .11241113    .05083997    .05173601    .12001698    .15352488  .015596442 -.005522388
                  .07533263    .08246953     .3164574      .320403   .020806944   .03825931  -.027562324  -.005051854    -.0778321  -.067371085 -.001401338  -.13702537
                 -.03919758   -.04413805   -.10441796    -.0729718   -.09871516   -.1137645   -.04444457  -.069699295   -.02802208    -.0378944 -.008620298   .04052174
                  .06712909    .05488251    .02990801    .05340606    .14464203   .14485054     .1546297     .1973386    .10255604    .09685634   .04581738   .04462644
                  .09122027    .09489667    .28565454     .2553083    .09811682   .22822624     .0666334    .06297087    .09850914    .14374436   .03973568     -.00272
                 -.06904627   -.08235581   .036592104    .06613888   .034956098   .03040757     .0450689   .022513844    .08742993    .07769005  .032609344  -.10957805
               -.0010226615    .05596735   -.04488378   -.05164978  -.017602434 -.015999822    .05338676   .035700433   .025620636    .07526974 -.003950925   .07513513
                  .06591474    .07430313    .07666447      .066182 -.0022166944 -.005087604   -.01070926   -.01785186   .009655667   .011435011   .01076275   .01893749
                 -.03654728  -.013483796   -.06920492   -.05080765   -.04490763  -.02913994   -.12294122   -.13522303   -.11620212  -.071497105  -.05046159  .022532895
                  .05432805    .02129159  -.007824223 -.0001135127   .026768256  .028928647    .06875625    .05878505    .07788658    .05317609  .028705105 -.034904294
                -.021210345   -.04434619     .0400013    .08290202    .03439759  .012775147   .019857846    .02131161    .06299546    .04206141 -.000492759         -.1
                  .04593057    .05355465   .036070883   .035338785    .04121177   .05911014    .02182684    .06205535     .0306966   .031417575   .01748928           0
                  .06402377    .09074234   .017035993   .018673256  -.006892527 -.008528514    .05310766    .03718807    .01518506   .016142072   .03367931  -.00462963
               -.0008634874  -.017124832   .012288786   .016581304   .022670185  .011694073   .002509139    .01356765  .0010720422   .006586197   .02104664 -.009302326
                 -.16025718   -.17407355    .01861758   .002882909    .04437076  .032403354     .0845593    .09163754     .0546896    .02472729  .009295903   .02967136
                  .06491467    .08848898   .018101824   .019244917    .07545424   .10509348    .04705809  -.006433318   -.05429295   -.05182991  .015956363  .012219588
                  .13717386    .14299387   -.05481096   -.06764241   -.02974429  -.02817233   .002695387   .001666678 -.0022348154 -.0035223535  .001926339  -.02702703
                 .010593375    .01315797    .03796482   .035461027   .012470516   .01780226  -.003759077   -.02321159   .014391478   .064276546  .003958267 -.012407407
                 .027143093   .018283656   -.14655557   -.14019935   -.07493122  -.09178464  -.012012037 -.0025534006  -.010534252   -.00760183   .00627381  -.14682168
                  .07843146     .0827109    .12697332    .11007153   -.03775569 -.022146804    .04135363      .085094    .02862696    .04061469  .017782183   .06593407
                -.033498652   -.03803785   -.07761273   -.05089051  -.019360857  -.05240043   -.05887474   -.05995676   .022229396  -.036720958 -.008931396  .010309278
                 -.03444993  -.033050265     .0118049 -.0041329064   -.01334389   -.0077434   .034621052    .01241764    .07535622    .06478325   .06779242  .015306122
                  .08982436    .07796862     .3503772     .3321544    .24415623    .2405888    .05385415    .14550373   -.06417959    .03794419   .03933193  -.19095477
                 -.04498287   -.05017506   .019882595   .031571873   -.03690799 -.030078683   -.07003552   -.06484095   -.04825789   -.04666756 -.001273156   .08074534
                 -.07062563  -.034556508   -.15291037    -.1608362   -.05569534  -.05905105    -.0876416    -.0809481   -.07204409  -.072459206   -.0618791   .04597701
                 -.04108484   -.04448353   -.08472862   -.10555337   -.04252707    -.099456    .02114636  -.033777736  -.013974559   -.01126147 -.031409003   .06043956
                  .16362718    .15840815  -.030529147   -.04783507    -.0758194   -.0479073   -.04122576  -.031652644   .004050429   .016922483 -.001836653    .0880829
                 -.01520417   -.04935718   -.05556374   .008469924   .014872017  -.02781137    -.1838731   -.17341676   -.05286881   -.05677932  -.03080926 -.023809524
                  .14825472    .16980487   .009420735    .04342137    .06823432   .02074468  -.005236849   .037133135   -.07801557   -.11043482   .02365827   .08292683
                 -.13042435   -.13187778 -.0002611185   .009433928   -.03952984 -.030094165    .12086282     .1497444  -.020142464  -.028265746   .01381636   -.0899099
                 .014201035   .009493854    .01301928  -.005932443   -.12060607   -.1172693   .009390165   -.01758779    .01166687   .016967362 -.006963575   .23401307
                 .025688456   .013366709   -.11582106    -.1292953   -.01813987  -.01705804   .012117738   -.03865504  -.029785136   -.02266691  -.02424476 -.033852078
                  .09906305      .077659   .030445484    .02187163     .0752309  .005413346     .0896435    .05383314     .1875305    .28424215   .03849168  -.02457655
                  .14727205    .12196179    .03881901   -.03446994 -.0026500665  .018915534   -.02835805  -.034883905   .016321074   .017445698  .022849614   .04613551
                  .06038489    .05570481    .12844995     .2915827    .15274623   .19047496    .07079318     .0926249    .05838854     .0583105   .05464041  .011879577
                 -.03801994    -.0511527    .02901731    .07733157   -.02142374 -.004599522  -.033171967   -.07649586   -.04736259    -.0540581  -.01371811  -.04310067
                 -.08521917   -.04588118   -.01253918   -.04215752    .02731782   .05687196  -.019924374    -.0753694    .02775079     .0184914  .003942049   .01697479
                 -.11821023   -.11270754 -.0020688411    .00558737   -.05361249   -.0581445  -.029093096  -.027105644    .01526294   .012210313 -.002071498 -.016691456
              end

              Comment


              • #8
                Ah, yes. In the original example data, the market price variable was called market. But in this example, and apparently in the real data set, it is called mkt. So just changing market in the code to mkt solves the problem:

                Code:
                gen `c(obs_t)' obs_no = _n
                reshape long vw_mean__mom_d@_rt ew_mean__mom_d@_rt, i(obs_no) j(decile)
                reshape long @_mean__mom_d_rt, i(obs_no decile) j(weight) string
                rename _mean__mom_d_rt rt
                
                capture program drop one_weighted_decile
                program define one_weighted_decile
                    regress rt
                    gen mean_rt = _b[_cons]
                    gen t_stat = mean_rt/_se[_cons]
                    regress rt mkt
                    gen capm_alpha = _b[_cons]
                    gen capm_tstat = capm_alpha/_se[_cons]
                    gen capm_beta = _b[mkt]
                    gen delta = rt - rf
                    summ delta
                    gen sharpe_ratio = r(mean)/r(sd)
                    gen treynors_ratio = r(mean)/capm_beta
                    keep decile weight mean_rt t_stat capm_alpha capm_tstat sharpe_ratio treynors_ratio
                    keep in 1
                end
                
                runby one_weighted_decile, by(decile weight) status

                Comment

                Working...
                X