Announcement

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

  • Computing Cumulative Average Abnormal Returns (CAAR)

    Dear all,

    I'm having trouble computing the CAAR in Stata and I hope you can help me!

    The problem: I need to compute the CAAR automatically, which is the cumulative of AAR, but I can't seem to get it right.
    I tried:

    egen caar = sum(aar)

    but then I get only one value for CAAR, since every AAR is summed. How do I get Stata to compute CAAR automatically (as shown in the table below, which I calculated by hand)?
    Company Time AAR CAAR
    A 1 0,1 0,1
    B 1 0,1 0,1
    C 1 0,1 0,1
    A 2 -0,2 -0,1
    B 2 -0,2 -0,1
    C 2 -0,2 -0,1
    A 3 0,5 0,4
    B 3 0,5 0,4
    C 3 0,5 0,4

  • #2
    The sum() function of egen does not give cumulative sums. It's the old name for total(),

    You may want

    Code:
    bysort Company (Time) : gen CAAR = sum(AAR)

    Comment


    • #3
      Thank you very much! Worked perfectly!

      Comment


      • #4
        Nick,

        I am facing a similar problem using the total() function.
        Currently I am using the following code:
        Code:
        bys month: egen VW_MSCI_BHAR_YEAR = total(VW_MSCI_BHAR) if year == 2000
        When trying to replace if there is a different year using the following code:
        Code:
        bys month: replace VW_MSCI_BHAR_YEAR = total(VW_MSCI_BHAR) if year == 2001
        the following error occurs: unknown function total()


        Now I have tried to use the sum() function the following way:
        Code:
        bys month: gen VW_MSCI_BHAR_YEAR = sum(VW_MSCI_BHAR) if year == 2000
        Unfortunately the sum() function produces different results. Any idea what the problem might be?

        Comment


        • #5
          Two problems here:

          1. The sum() function which can, and should only, be referred to outside egen returns cumulative or running sums, which is not at all what you want.

          2. The total() function which can, and should only, be referred to inside egen returns totals.

          Terminology is overloaded here, as function thus means different beasts

          (a) inside egen

          (b) outside egen

          (c) in Mata for that matter.

          I am simplifying here, believe it or not, but that's most of the truth.

          All that said, it seems possible that your problem is solved just by

          Code:
           
           bys month year: egen VW_MSCI_BHAR_YEAR = total(VW_MSCI_BHAR)
          but as you give no examples of your data and don't explain what month is (month of year? monthly date?) I am guessing. See also FAQ Advice #12.

          Comment


          • #6
            thanks for your answer so far Nick.

            I want to calculate the total return, by year of issuing, when holding a portfolios of IPOs after 36 months. I will try to explain below:

            I have a set of panel data containing information on initial public offerings (IPO)
            For each IPO I have collected 36 months of pricing data and calculated abnormal returns in several different ways, but I will just show one of the methods (the others are similar just using different benchmarks and equal weights instead of value weights).

            The variable VW_MSCI_BHAR represents the value weighed buy-and-hold abnormal return. Where "abnormal" is the excess over an MSCI shares index used as benchmark. I will show how I calculated this variable:

            First I calculated "Buy-and-hold" (BHR) returns for each company. These are the compounded monthly returns. I used the following formula to do so:
            Code:
            by id (month), sort: gen double return = price/L.price - 1
            gen return1 = return + 1
            by id (month), sort: gen double BHR = 1 if _n == 1
            by id (month): replace BHR = L.BHR*return1 if _n > 1
            drop return return1
            Next I computed the BHR for the bechmark (the MSCI Europe index):
            Code:
            by id (month), sort: gen double return = MSCIEUROPE/L.MSCIEUROPE - 1
            gen MSCIReturn = return + 1
            by id (month), sort: gen double BHR_MSCI = 1 if _n == 1
            by id (month): replace BHR_MSCI = L.BHR_MSCI*MSCIReturn if _n > 1
            drop return MSCIReturn
            Now the MSCI_BHAR is constructed as:
            Code:
            gen MSCI_BHAR = (BHR - BHR_MSCI)
            VW is the market value of the company at time of the IPO relative to the market value of all IPOs at time of the offering:
            Code:
            bys month: egen totalmv = total(mv) if month==0
            replace totalmv =totalmv[_n-1] if missing(totalmv)
            sort id month
            bys id: gen mvinitial=mv[1]
            bys id: gen value_weight = mvinitial/totalmv
            drop if value_weight==.
            sort id month
            The VW_MSCI_BHAR is calculated next by:
            Code:
            bys month id: gen VW_MSCI_BHAR = value_weight*MSCI_BHAR
            Now I would like to calculate the total value weighted, buy-and-hold abnormal return (VW_MSCI_BHAR), by year of the IPO.
            The variable year is constructed from the IPO date.
            Code:
            gen year= year(IPOdate)
            I hope you understand the methodology I use, otherwise please ask and I will try to explain it again differently.
            Last edited by Bram Smith; 30 Jun 2016, 11:10.

            Comment


            • #7
              Originally posted by Nick Cox View Post
              The sum() function of egen does not give cumulative sums. It's the old name for total(),

              You may want

              Code:
              bysort Company (Time) : gen CAAR = sum(AAR)
              Dear mr. Cox,

              I was too quick with my response that it worked perfectly, as I now see your suggested code generates exactly the same column as AAR.

              Company
              Time AAR CAAR
              A 1 0,1 0,1
              B 1 0,1 0,1
              C 1 0,1 0,1
              A 2 -0,2 -0,2
              B 2 -0,2 -0,2
              C 2 -0,2 -0,2
              A 3 0,5 0,5
              B 3 0,5 0,5
              C 3 0,5 0,5
              My code input was:

              bysort conm t: gen caar = sum(aar) , where conm is company name and t is time
              As I want:

              Company
              Time AAR CAAR
              A 1 0,1 0,1
              B 1 0,1 0,1
              C 1 0,1 0,1
              A 2 -0,2 -0,1
              B 2 -0,2 -0,1
              C 2 -0,2 -0,1
              A 3 0,5 0,4
              B 3 0,5 0,4
              C 3 0,5 0,4
              Do you have any suggestions on how to calculate this? As the previous suggested code did not work.

              I'm hoping for a repsonse.

              Comment


              • #8
                Sorry, I got lost in the middle of #6 as I stopped the study of economics in 1969 (A level Economics, Grade A, for those who know what that means).

                But from #7 it is clear that what I didn't suggest didn't work.... Story of my life.

                More seriously, the parentheses ( ) you omitted make a big difference to the meaning. As in a concurrent thread, by: is a powerful but subtle construct. See e.g. http://www.stata-journal.com/sjpdf.h...iclenum=pr0004

                Code:
                bysort conm (t): gen caar = sum(aar)

                Comment


                • #9
                  Originally posted by Nick Cox View Post
                  Sorry, I got lost in the middle of #6 as I stopped the study of economics in 1969 (A level Economics, Grade A, for those who know what that means).

                  But from #7 it is clear that what I didn't suggest didn't work.... Story of my life.

                  More seriously, the parentheses ( ) you omitted make a big difference to the meaning. As in a concurrent thread, by: is a powerful but subtle construct. See e.g. http://www.stata-journal.com/sjpdf.h...iclenum=pr0004

                  Code:
                  bysort conm (t): gen caar = sum(aar)
                  Dear Mr. Cox,

                  Now, it works perfectly! I wasn't aware the parentheses made such a difference.

                  Thank you very much!

                  P.s. I hope you realize the parts in the middle of this thread are from a whole other person.

                  Comment


                  • #10
                    Dear Mr Cox,

                    I want to generate AAR and CAAR plus the t-test. Please, could you assist me with the commands,
                    my AR and CAR appears as follows:
                    sort id date
                    gen abnormal_return=stock_ret-predicted_return if event_window==1
                    by id: egen cumulative_abnormal_return = sum(abnormal_return)

                    Comment


                    • #11
                      Mr Cox, thank you for help first of all. I'm trying to do something similar as the original poster. However, if I run your code all the AAR (which are the same for different companies at the same time t since they are grouped by t) get added up in the CAAR row. Meaning for example that the CAAR row contains the following
                      Time AAR CAAR
                      A 1 0,1 0,1
                      B 1 0,1 0,2
                      C 1 0,1 0,3
                      A 2 -0,2 0,1
                      B 2 -0,2 -0,1
                      C 2 -0,2 -0,3
                      A 3 0,5 0,2
                      B 3 0,5 0,7
                      C 3 0,5 1,2
                      Can you give me any tips how I could prevent every AAR value from adding up and rather just use one time the average per calculated average?
                      Regards

                      Comment

                      Working...
                      X