Announcement

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

  • Annual return from monthly return.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear input double
     permno date str8(ncusip cusip)          vwretd
    10001 10255 "39040610" "36720410"    .04488041
    10001 10286 "39040610" "36720410"    .05169475
    10001 10317 "39040610" "36720410"   -.01659759
    10001 10346 "39040610" "36720410"    .01099083
    10001 10378 "39040610" "36720410"   .000447785
    10001 10408 "39040610" "36720410"    .05145973
    10001 10437 "39040610" "36720410"  -.007271962
    10001 10470 "39040610" "36720410"   -.02800588
    10001 10500 "39040610" "36720410"    .03720232
    10001 10531 "39040610" "36720410"    .01764623
    10001 10561 "39040610" "36720410"   -.01641204
    10001 10591 "39040610" "36720410"    .02107465
    10001 10623 "39040610" "36720410"    .06610259
    10001 10651 "39040610" "36720410"   -.01644639
    10001 10682 "39040610" "36720410"    .02146523
    10001 10710 "39040610" "36720410"    .04820446
    10001 10743 "39040610" "36720410"    .03933809
    10001 10773 "39040610" "36720410"  -.004866142
    10001 10804 "39040610" "36720410"    .07713073
    10001 10835 "39040610" "36720410"     .0221267
    10001 10864 "39040610" "36720410"  -.001474362
    10001 10896 "39040610" "36720410"   -.02928529
    10001 10926 "39040610" "36720410"     .0178139
    10001 10955 "39040610" "36720410"    .01829512
    10001 10988 "39040610" "36720410"   -.07011517
    10001 11016 "39040610" "36720410"    .01490096
    10001 11046 "39040610" "36720410"    .02414006
    10001 11077 "39040610" "36720410"    -.0282857
    10001 11108 "39040610" "36720410"    .08893429
    10001 11137 "39040610" "36720410"  -.004196256
    10001 11169 "39040610" "36720410"  -.009402919
    10001 11200 "39040610" "36720410"   -.09190542
    10001 11228 "39040610" "36720410"   -.05384322
    10001 11261 "39040610" "36720410"   -.01250398
    10001 11291 "39040610" "36720410"    .06574359
    10001 11322 "39040610" "36720410"    .02951265
    10001 11353 "39040610" "36720410"    .04907785
    10001 11381 "39040610" "36720410"    .07584678
    10001 11409 "39040610" "36720410"    .02892273
    10001 11442 "39040610" "36720410"   .003314882
    10001 11473 "39040610" "36720410"     .0407327
    10001 11501 "39040610" "36720410"   -.04402925
    10001 11534 "39040610" "36720410"    .04679512
    10001 11564 "39040610" "36720410"     .0268165
    10001 11595 "39040610" "36720410"   -.01097486
    10001 11626 "39040610" "36720410"    .01781452
    10001 11655 "39040610" "36720410"   -.03727527
    10001 11687 "39040610" "36720410"     .1067778
    10001 11718 "39040610" "36720410"  -.001182341
    10001 11746 "39040610" "36720410"    .01335434
    10001 11778 "39040610" "36720410"   -.02369961
    10001 11808 "39040610" "36720410"    .01341884
    10001 11837 "39040610" "36720410"   .006438549
    10001 11869 "39040610" "36720410"   -.01927053
    10001 11900 "39040610" "36720410"    .03989998
    10001 11931 "39040610" "36720410"   -.02081965
    10001 11961 "39040610" "36720410"    .01244722
    10001 11991 "39040610" "36720410"    .01098552
    10001 12022 "39040610" "36720410"    .04019304
    10001 12053 "39040610" "36720410"    .01776835
    10001 12082 "39040610" "36720410"    .01264374
    10001 12110 "39040610" "36720410"   .005402277
    10001 12143 "39040610" "36720410"     .0251157
    10001 12173 "39040610" "36720410"   -.02540042
    10001 12201 "39040610" "36720410"    .02959926
    10001 12234 "39040610" "36720410"   .005440016
    10001 12264 "39040610" "36720410" -.0007919354
    10001 12296 "39040610" "36720410"    .03947853
    10001 12326 "39040610" "36720410"  .0006406767
    10001 12355 "39040610" "36720410"    .01806427
    10001 12387 "29274A10" "36720410"   -.01760636
    10001 12418 "29274A10" "36720410"    .01951495
    10001 12449 "29274A10" "36720410"    .03146612
    10001 12477 "29274A10" "36720410"   -.02422607
    10001 12508 "29274A10" "36720410"   -.04579477
    10001 12537 "29274A10" "36720410"   .009477681
    10001 12569 "29274A10" "36720410"   .009360213
    10001 12599 "29274A10" "36720410"   -.02790886
    10001 12628 "29274A10" "36720410"    .03063324
    10001 12661 "29274A10" "36720410"    .04259737
    10001 12691 "29274A10" "36720410"   -.01836337
    10001 12722 "29274A10" "36720410"    .01451999
    10001 12752 "29274A10" "36720410"   -.03721879
    10001 12782 "29274A10" "36720410"    .01260929
    10001 12814 "29274A10" "36720410"    .02039915
    10001 12842 "29274A10" "36720410"    .03961473
    10001 12873 "29274A10" "36720410"    .02704092
    10001 12901 "29274A10" "36720410"    .02504808
    10001 12934 "29274A10" "36720410"    .03400705
    10001 12964 "29274A10" "36720410"    .03117276
    10001 12995 "29274A10" "36720410"    .04078258
    10001 13026 "29274A10" "36720410"   .009303724
    10001 13055 "29274A10" "36720410"     .0363627
    10001 13087 "29274A10" "36720410"   -.01131678
    10001 13117 "29274A10" "36720410"    .04280756
    10001 13146 "29274A10" "36720410"    .01519028
    10001 13179 "29274A10" "36720410"     .0281413
    10001 13208 "29274A10" "36720410"    .01631008
    10001 13237 "29274A10" "36720410"    .01092697
    10001 13269 "29274A10" "36720410"    .02551078
    end
    format %td date
    I want to calculate annual cumulative return. For example, Annual_return=(1+vwretx_m1)*(1+vwretx_m2)*........ ...........(1+vwretx_m12)-1
    I have tried the following code:

    gen year=year(date)
    bysort permno year: gen anret=log(vwretx+1)
    What I get from this code does not match with cumulative value calculated from excel. Please suggest me.

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double permno date str8(ncusip cusip)          vwretd
    10001 10255 "39040610" "36720410"    .04488041
    10001 10286 "39040610" "36720410"    .05169475
    10001 10317 "39040610" "36720410"   -.01659759
    10001 10346 "39040610" "36720410"    .01099083
    10001 10378 "39040610" "36720410"   .000447785
    10001 10408 "39040610" "36720410"    .05145973
    10001 10437 "39040610" "36720410"  -.007271962
    10001 10470 "39040610" "36720410"   -.02800588
    10001 10500 "39040610" "36720410"    .03720232
    10001 10531 "39040610" "36720410"    .01764623
    10001 10561 "39040610" "36720410"   -.01641204
    10001 10591 "39040610" "36720410"    .02107465
    10001 10623 "39040610" "36720410"    .06610259
    10001 10651 "39040610" "36720410"   -.01644639
    10001 10682 "39040610" "36720410"    .02146523
    10001 10710 "39040610" "36720410"    .04820446
    10001 10743 "39040610" "36720410"    .03933809
    10001 10773 "39040610" "36720410"  -.004866142
    10001 10804 "39040610" "36720410"    .07713073
    10001 10835 "39040610" "36720410"     .0221267
    10001 10864 "39040610" "36720410"  -.001474362
    10001 10896 "39040610" "36720410"   -.02928529
    10001 10926 "39040610" "36720410"     .0178139
    10001 10955 "39040610" "36720410"    .01829512
    10001 10988 "39040610" "36720410"   -.07011517
    10001 11016 "39040610" "36720410"    .01490096
    10001 11046 "39040610" "36720410"    .02414006
    10001 11077 "39040610" "36720410"    -.0282857
    10001 11108 "39040610" "36720410"    .08893429
    10001 11137 "39040610" "36720410"  -.004196256
    10001 11169 "39040610" "36720410"  -.009402919
    10001 11200 "39040610" "36720410"   -.09190542
    10001 11228 "39040610" "36720410"   -.05384322
    10001 11261 "39040610" "36720410"   -.01250398
    10001 11291 "39040610" "36720410"    .06574359
    10001 11322 "39040610" "36720410"    .02951265
    10001 11353 "39040610" "36720410"    .04907785
    10001 11381 "39040610" "36720410"    .07584678
    10001 11409 "39040610" "36720410"    .02892273
    10001 11442 "39040610" "36720410"   .003314882
    10001 11473 "39040610" "36720410"     .0407327
    10001 11501 "39040610" "36720410"   -.04402925
    10001 11534 "39040610" "36720410"    .04679512
    10001 11564 "39040610" "36720410"     .0268165
    10001 11595 "39040610" "36720410"   -.01097486
    10001 11626 "39040610" "36720410"    .01781452
    10001 11655 "39040610" "36720410"   -.03727527
    10001 11687 "39040610" "36720410"     .1067778
    10001 11718 "39040610" "36720410"  -.001182341
    10001 11746 "39040610" "36720410"    .01335434
    10001 11778 "39040610" "36720410"   -.02369961
    10001 11808 "39040610" "36720410"    .01341884
    10001 11837 "39040610" "36720410"   .006438549
    10001 11869 "39040610" "36720410"   -.01927053
    10001 11900 "39040610" "36720410"    .03989998
    10001 11931 "39040610" "36720410"   -.02081965
    10001 11961 "39040610" "36720410"    .01244722
    10001 11991 "39040610" "36720410"    .01098552
    10001 12022 "39040610" "36720410"    .04019304
    10001 12053 "39040610" "36720410"    .01776835
    10001 12082 "39040610" "36720410"    .01264374
    10001 12110 "39040610" "36720410"   .005402277
    10001 12143 "39040610" "36720410"     .0251157
    10001 12173 "39040610" "36720410"   -.02540042
    10001 12201 "39040610" "36720410"    .02959926
    10001 12234 "39040610" "36720410"   .005440016
    10001 12264 "39040610" "36720410" -.0007919354
    10001 12296 "39040610" "36720410"    .03947853
    10001 12326 "39040610" "36720410"  .0006406767
    10001 12355 "39040610" "36720410"    .01806427
    10001 12387 "29274A10" "36720410"   -.01760636
    10001 12418 "29274A10" "36720410"    .01951495
    10001 12449 "29274A10" "36720410"    .03146612
    10001 12477 "29274A10" "36720410"   -.02422607
    10001 12508 "29274A10" "36720410"   -.04579477
    10001 12537 "29274A10" "36720410"   .009477681
    10001 12569 "29274A10" "36720410"   .009360213
    10001 12599 "29274A10" "36720410"   -.02790886
    10001 12628 "29274A10" "36720410"    .03063324
    10001 12661 "29274A10" "36720410"    .04259737
    10001 12691 "29274A10" "36720410"   -.01836337
    10001 12722 "29274A10" "36720410"    .01451999
    10001 12752 "29274A10" "36720410"   -.03721879
    10001 12782 "29274A10" "36720410"    .01260929
    10001 12814 "29274A10" "36720410"    .02039915
    10001 12842 "29274A10" "36720410"    .03961473
    10001 12873 "29274A10" "36720410"    .02704092
    10001 12901 "29274A10" "36720410"    .02504808
    10001 12934 "29274A10" "36720410"    .03400705
    10001 12964 "29274A10" "36720410"    .03117276
    10001 12995 "29274A10" "36720410"    .04078258
    10001 13026 "29274A10" "36720410"   .009303724
    10001 13055 "29274A10" "36720410"     .0363627
    10001 13087 "29274A10" "36720410"   -.01131678
    10001 13117 "29274A10" "36720410"    .04280756
    10001 13146 "29274A10" "36720410"    .01519028
    10001 13179 "29274A10" "36720410"     .0281413
    10001 13208 "29274A10" "36720410"    .01631008
    10001 13237 "29274A10" "36720410"    .01092697
    10001 13269 "29274A10" "36720410"    .02551078
    end
    format %td date
    
    //    EXTRACT MONTH AND YEAR FROM DATE
    gen year = yofd(date)
    gen month = mofd(date)
    format month %tm
    
    gen log_monthly_factor = log(1+vwretd)
    by permno year, sort: egen double log_yearly_factor = total(log_monthly_factor)
    gen double yearly_return = exp(log_yearly_factor) - 1
    By the way, in copying the -dataex- output into the Forum editor you somehow got the spacing mangled. I've fixed it in this response.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double permno date str8(ncusip cusip) vwretd
      10001 10255 "39040610" "36720410" .04488041
      10001 10286 "39040610" "36720410" .05169475
      10001 10317 "39040610" "36720410" -.01659759
      10001 10346 "39040610" "36720410" .01099083
      10001 10378 "39040610" "36720410" .000447785
      10001 10408 "39040610" "36720410" .05145973
      10001 10437 "39040610" "36720410" -.007271962
      10001 10470 "39040610" "36720410" -.02800588
      10001 10500 "39040610" "36720410" .03720232
      10001 10531 "39040610" "36720410" .01764623
      10001 10561 "39040610" "36720410" -.01641204
      10001 10591 "39040610" "36720410" .02107465
      10001 10623 "39040610" "36720410" .06610259
      10001 10651 "39040610" "36720410" -.01644639
      10001 10682 "39040610" "36720410" .02146523
      10001 10710 "39040610" "36720410" .04820446
      10001 10743 "39040610" "36720410" .03933809
      10001 10773 "39040610" "36720410" -.004866142
      10001 10804 "39040610" "36720410" .07713073
      10001 10835 "39040610" "36720410" .0221267
      10001 10864 "39040610" "36720410" -.001474362
      10001 10896 "39040610" "36720410" -.02928529
      10001 10926 "39040610" "36720410" .0178139
      10001 10955 "39040610" "36720410" .01829512
      10001 10988 "39040610" "36720410" -.07011517
      10001 11016 "39040610" "36720410" .01490096
      10001 11046 "39040610" "36720410" .02414006
      10001 11077 "39040610" "36720410" -.0282857
      10001 11108 "39040610" "36720410" .08893429
      10001 11137 "39040610" "36720410" -.004196256
      10001 11169 "39040610" "36720410" -.009402919
      10001 11200 "39040610" "36720410" -.09190542
      10001 11228 "39040610" "36720410" -.05384322
      10001 11261 "39040610" "36720410" -.01250398
      10001 11291 "39040610" "36720410" .06574359
      10001 11322 "39040610" "36720410" .02951265
      10001 11353 "39040610" "36720410" .04907785
      10001 11381 "39040610" "36720410" .07584678
      10001 11409 "39040610" "36720410" .02892273
      10001 11442 "39040610" "36720410" .003314882
      10001 11473 "39040610" "36720410" .0407327
      10001 11501 "39040610" "36720410" -.04402925
      10001 11534 "39040610" "36720410" .04679512
      10001 11564 "39040610" "36720410" .0268165
      10001 11595 "39040610" "36720410" -.01097486
      10001 11626 "39040610" "36720410" .01781452
      10001 11655 "39040610" "36720410" -.03727527
      10001 11687 "39040610" "36720410" .1067778
      10001 11718 "39040610" "36720410" -.001182341
      10001 11746 "39040610" "36720410" .01335434
      10001 11778 "39040610" "36720410" -.02369961
      10001 11808 "39040610" "36720410" .01341884
      10001 11837 "39040610" "36720410" .006438549
      10001 11869 "39040610" "36720410" -.01927053
      10001 11900 "39040610" "36720410" .03989998
      10001 11931 "39040610" "36720410" -.02081965
      10001 11961 "39040610" "36720410" .01244722
      10001 11991 "39040610" "36720410" .01098552
      10001 12022 "39040610" "36720410" .04019304
      10001 12053 "39040610" "36720410" .01776835
      10001 12082 "39040610" "36720410" .01264374
      10001 12110 "39040610" "36720410" .005402277
      10001 12143 "39040610" "36720410" .0251157
      10001 12173 "39040610" "36720410" -.02540042
      10001 12201 "39040610" "36720410" .02959926
      10001 12234 "39040610" "36720410" .005440016
      10001 12264 "39040610" "36720410" -.0007919354
      10001 12296 "39040610" "36720410" .03947853
      10001 12326 "39040610" "36720410" .0006406767
      10001 12355 "39040610" "36720410" .01806427
      10001 12387 "29274A10" "36720410" -.01760636
      10001 12418 "29274A10" "36720410" .01951495
      10001 12449 "29274A10" "36720410" .03146612
      10001 12477 "29274A10" "36720410" -.02422607
      10001 12508 "29274A10" "36720410" -.04579477
      10001 12537 "29274A10" "36720410" .009477681
      10001 12569 "29274A10" "36720410" .009360213
      10001 12599 "29274A10" "36720410" -.02790886
      10001 12628 "29274A10" "36720410" .03063324
      10001 12661 "29274A10" "36720410" .04259737
      10001 12691 "29274A10" "36720410" -.01836337
      10001 12722 "29274A10" "36720410" .01451999
      10001 12752 "29274A10" "36720410" -.03721879
      10001 12782 "29274A10" "36720410" .01260929
      10001 12814 "29274A10" "36720410" .02039915
      10001 12842 "29274A10" "36720410" .03961473
      10001 12873 "29274A10" "36720410" .02704092
      10001 12901 "29274A10" "36720410" .02504808
      10001 12934 "29274A10" "36720410" .03400705
      10001 12964 "29274A10" "36720410" .03117276
      10001 12995 "29274A10" "36720410" .04078258
      10001 13026 "29274A10" "36720410" .009303724
      10001 13055 "29274A10" "36720410" .0363627
      10001 13087 "29274A10" "36720410" -.01131678
      10001 13117 "29274A10" "36720410" .04280756
      10001 13146 "29274A10" "36720410" .01519028
      10001 13179 "29274A10" "36720410" .0281413
      10001 13208 "29274A10" "36720410" .01631008
      10001 13237 "29274A10" "36720410" .01092697
      10001 13269 "29274A10" "36720410" .02551078
      end
      format %td date
      
      // EXTRACT MONTH AND YEAR FROM DATE
      gen year = yofd(date)
      gen month = mofd(date)
      format month %tm
      
      gen log_monthly_factor = log(1+vwretd)
      by permno year, sort: egen double log_yearly_factor = total(log_monthly_factor)
      gen double yearly_return = exp(log_yearly_factor) - 1
      By the way, in copying the -dataex- output into the Forum editor you somehow got the spacing mangled. I've fixed it in this response.
      Thank you so much. You are awesome. Is there any good book on stata that explains data manipulation technique? I look forward to your advice.

      Comment


      • #4
        Cross-posted at https://stackoverflow.com/questions/...monthly-return

        Our policy on cross-posting is explicit in the FAQ Advice: you are asked to tell us about it.

        Comment


        • #5
          Thank you so much. You are awesome. Is there any good book on stata that explains data manipulation technique? I look forward to your advice.
          There are several available in the Bookstore at stata.com. One that might be particularly helpful for you is C. Baum's Introduction to Stata Programming.

          Comment


          • #6
            You can also use asrol (from SSC) for this task. See
            Code:
            ssc install asrol
            gen year = yofd(date)
            bys permno year : asrol vwretd, s(product) add(1)
            Regards
            --------------------------------------------------
            Attaullah Shah, PhD.
            Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
            FinTechProfessor.com
            https://asdocx.com
            Check out my asdoc program, which sends outputs to MS Word.
            For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

            Comment


            • #7
              Not my field at all, but the original data look like log returns to me. That being so, you need to add them, not multiply (modulo adding 1, and so forth).

              Comment


              • #8
                Nick

                I don't think those are log returns. I think they are signed relative changes in values. In what Mr. Islam worte in #1 it appeared that he was looking to calculate not the product of those numbers but the product of (1+those numbers). (Of course, those numbers are also petty small in magnitude and log(1+x) will not differ much from x itself.)



                Comment


                • #9
                  Clyde: It's good to think they make sense. I don't know why they are called returns if they aren't,

                  Comment

                  Working...
                  X