Announcement

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

  • How to code to calculate Buy-and-hold Abnormal Return (BHAR)

    We use the income from May of T+1 to April of T+2 as T annual income.BHAR is equal to the multiplier of each company's 12-month revenue in a year, and then subtracts the 12-month revenue multiplication of the market in a year.For example, A company's 2015 BHAR is equal to the company's monthly yield from May 2016 to April 2017, and then subtracted the yield from May 2016 to April 2017.This is too complicated, I really can't figure it out, so ask questions.IT is Individual income.MT is market income
    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6 code str7 date double(IT MT)
    "000002" "2009-01"  .091473  .157394
    "000002" "2009-02"  .015625   .08893
    "000002" "2009-03"  .158042  .223024
    "000002" "2009-04"  .024155  .076364
    "000002" "2009-05"  .148585  .071731
    "000002" "2009-06"  .314909  .088737
    "000002" "2009-07"  .047843  .148047
    "000002" "2009-08" -.296407  -.15897
    "000002" "2009-09"  .108511  .045235
    "000002" "2009-10"  .104607  .120721
    "000002" "2009-11"  .001738  .146828
    "000002" "2009-12" -.062446  .025708
    "000002" "2010-01" -.135985 -.032345
    "000002" "2010-02"  .009636  .066523
    "000002" "2010-03"  .007423  .042699
    "000002" "2010-04" -.178947 -.070492
    "000002" "2010-05" -.066826 -.085053
    "000002" "2010-06" -.059639 -.092684
    "000002" "2010-07"  .222714  .152968
    "000002" "2010-08"  .015682  .091707
    "000002" "2010-09" -.002375  .014685
    "000002" "2010-10"  .154762  .092551
    "000002" "2010-11" -.161856  .008053
    "000002" "2010-12"   .01107   -.0194
    "000002" "2011-01" -.002433 -.049277
    "000002" "2011-02" -.004878  .097416
    "000002" "2011-03"  .064951 -.005443
    "000002" "2011-04" -.024166 -.029671
    "000002" "2011-05" -.063769 -.073427
    "000002" "2011-06"  .077806  .037579
    "000002" "2011-07" -.035503  .021129
    "000002" "2011-08"        0 -.028933
    "000002" "2011-09" -.111656 -.117144
    "000002" "2011-10"  .104972   .03965
    "000002" "2011-11"   -.1175 -.044145
    "000002" "2011-12"  .058074 -.155997
    "000002" "2012-01"  .024096  .007288
    "000002" "2012-02"  .082353  .130467
    "000002" "2012-03"        0 -.072395
    "000002" "2012-04"  .084541  .075331
    "000002" "2012-05"  .030067  .020294
    "000002" "2012-06" -.036757 -.064925
    "000002" "2012-07"   .05041 -.092077
    "000002" "2012-08" -.131094  .019197
    "000002" "2012-09"  .051122   .01457
    "000002" "2012-10" -.013049   .00558
    "000002" "2012-11"  .051683 -.108443
    "000002" "2012-12"  .156571  .166233
    "000002" "2013-01"  .186759  .065083
    "000002" "2013-02" -.000833  .043567
    "000002" "2013-03" -.103333 -.033948
    "000002" "2013-04"  .025093 -.032165
    "000002" "2013-05"  .102837   .13469
    "000002" "2013-06" -.177796 -.163374
    "000002" "2013-07" -.033503  .062773
    "000002" "2013-08" -.006303  .092286
    "000002" "2013-09" -.034884  .048109
    "000002" "2013-10"  .008762 -.020632
    "000002" "2013-11"  -.04886  .071771
    "000002" "2013-12" -.083333  -.03295
    "000002" "2014-01" -.080946  .005079
    "000002" "2014-02" -.089431  .043985
    "000002" "2014-03"  .203869 -.017824
    "000002" "2014-04" -.023486 -.012822
    "000002" "2014-05"  .142649  .024008
    "000002" "2014-06" -.032749  .040563
    "000002" "2014-07"  .197098  .092952
    "000002" "2014-08" -.078788  .060615
    "000002" "2014-09"  .006579  .143076
    "000002" "2014-10"  .023965  .023014
    "000002" "2014-11"  .159574  .063455
    "000002" "2014-12"  .275229 -.010609
    "000002" "2015-01" -.056115  .072194
    "000002" "2015-02" -.028201   .07249
    "000002" "2015-03"  .083922  .224049
    "000002" "2015-04"   .05644  .189475
    "000002" "2015-05" -.017123  .270192
    "000002" "2015-06"  .011847 -.076295
    "000002" "2015-07"  .010236 -.166447
    "000002" "2015-08" -.026798 -.131148
    "000002" "2015-09" -.077536  -.05459
    "000002" "2015-10"  .073841  .218789
    "000002" "2015-11"  .102414  .108848
    "000002" "2015-12"  .621102  .076944
    "000002" "2016-07" -.268932  .010287
    "000002" "2016-08"  .454492  .053706
    "000002" "2016-09"  .049739 -.003338
    "000002" "2016-10" -.047765   .04209
    "000002" "2016-11"  .082665  .037181
    "000002" "2016-12" -.238325 -.034747
    "000002" "2017-01"  .006326 -.017722
    "000002" "2017-02" -.007253  .052976
    "000002" "2017-03"  .002435 -.015306
    "000002" "2017-04" -.052478 -.056799
    "000002" "2017-05"  .090256 -.076485
    "000002" "2017-06"  .174506  .041879
    "000002" "2017-07" -.064077  .003885
    "000002" "2017-08"  .027624  .038274
    "000002" "2017-09"  .130004  .010294
    "000002" "2017-10"  .103238 -.010664
    end
    ------------------ copy up to and including the previous line ------------------

    Last edited by xipei li; 07 Mar 2019, 18:17.

  • #2
    You have asked the same question in yesterday's post. I think the FAQs warns against doing so.

    To get you going, you may be interested in reading the help file of asrol (downloadable from SSC) and its product function for finding products of values. The following steps might be helpful to you in solving the problem.

    1. Download asrol from ssc
    Code:
    ssc install asrol
    2. Create daily date, month variable, year variable and the forward year variable
    Code:
    gen mofd= mofd(date(date, "YM"))
    gen month =  month(date(date, "YM"))
    gen year = year(date(date, "YM"))
    * Create a forward year variable, you have to figure out the logic of months and year here
    3. use asrol
    Code:
    bys code fyear : asrol IT, stat(product) add(1)
    bys code fyear : asrol MT,  stat(product) add(1)
    * And then find the difference of the two variables created by asrol
    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


    • #3
      Thank you for pointing out my mistake. Thank you. Could you be more careful? Besides, I don't know how to do it even by multiplying.

      Comment


      • #4
        This is a very simple manual way to approach it and you should be able to follow the code.

        1) Panel your data:
        Code:
        egen firm=group(companykey)
        gen year=substr(date,1,4)
        gen month=substr(date,6,2)
        gen day="20" // Arbitrary day that works in any given month
        
        gen tempdate = year + "/" + month + "/" day
        gen date2 = date(temp,"YMD")
        format date2 %td
        drop year month day tempdate
        
        gen month=mofd(date2)
        
        xtset firm month
        2) Assuming that IT is firm-specific and MT is the benchmark, create adjusted return and create compound buy-and-hold adjusted returns for the year ending each month in your data:
        Code:
        gen adj_it = it - mt
        gen compound = (1 + adj_it) * (1 + l.adj_it)
        
        forvalues i=2/11 {
              replace compound = compound * (1 + l`i'.adj_it)
        }
        
        gen bhar = compound - 1
        
        drop compound
        If you have breaks in your series (e.g., you're missing Feb and Sep in a given year) then you need to make a decision of how to deal with that because you lack sufficient data to compute BHARs for months that require lagged data from those periods. Hopefully the above code is helpful for you and demonstrates the simple approach to creating adjusted returns and compounding over a specific window of time

        Comment


        • #5
          Originally posted by Andrew Pierce View Post
          This is a very simple manual way to approach it and you should be able to follow the code.

          1) Panel your data:
          Code:
          egen firm=group(companykey)
          gen year=substr(date,1,4)
          gen month=substr(date,6,2)
          gen day="20" // Arbitrary day that works in any given month
          
          gen tempdate = year + "/" + month + "/" day
          gen date2 = date(temp,"YMD")
          format date2 %td
          drop year month day tempdate
          
          gen month=mofd(date2)
          
          xtset firm month
          2) Assuming that IT is firm-specific and MT is the benchmark, create adjusted return and create compound buy-and-hold adjusted returns for the year ending each month in your data:
          Code:
          gen adj_it = it - mt
          gen compound = (1 + adj_it) * (1 + l.adj_it)
          
          forvalues i=2/11 {
          replace compound = compound * (1 + l`i'.adj_it)
          }
          
          gen bhar = compound - 1
          
          drop compound
          If you have breaks in your series (e.g., you're missing Feb and Sep in a given year) then you need to make a decision of how to deal with that because you lack sufficient data to compute BHARs for months that require lagged data from those periods. Hopefully the above code is helpful for you and demonstrates the simple approach to creating adjusted returns and compounding over a specific window of time
          thank you so much!

          Comment

          Working...
          X