Announcement

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

  • How to claculate the accumulative value

    Dear All

    I am collecting some data. this data needs a calculation process
    I do understand the process but I don't know to do do a part of it.

    The equaion as follows
    ARi,t= Ri,t - MRt .....(1)
    where is i stands for a firm, and t for the date. Ri,t is daily return, MR is the markt return.
    Each firm or event (M&A) for each firm has even-dates like a range of time for example 5 or 10 days.

    Firm R MR evendate

    1 1.5 2 1-05-2021
    1 2 2 2-05-2021
    1 1 2 3-05-2021
    1 0.5 2 4-05-2021
    1 3 2 5-05-2021

    in Eq.(1) AR refers to the abnormal return after M&A.
    According to this I will have for example five values of ARi,t for each firm.
    Then I want to calculate the Accumulative ARi,t

    My question is whcih command for this
    I know that the accumulative value is calculated by adding the previous values to the current one so on.
    But here I have to limit it based on the evendate variable
    please someone give me the command for this

    Best,

  • #2
    The -sum()- function of generate calculates a running sum, while the -bysort- prefix restricts the calculation to each group.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte firm double r byte mr str9 evendate
    1 1.5 2 "1-05-2021"
    1   2 2 "2-05-2021"
    1   1 2 "3-05-2021"
    1  .5 2 "4-05-2021"
    1   3 2 "5-05-2021"
    end
    
    gen edate= daily(evendate, "DMY"), after(firm)
    format edate %tdD-N-CY
    bys firm (edate): gen wanted= sum(r - mr)
    Res.:

    Code:
    . l, sepby(firm)
    
         +---------------------------------------------------+
         | firm        edate     r   mr    evendate   wanted |
         |---------------------------------------------------|
      1. |    1   01-05-2021   1.5    2   1-05-2021      -.5 |
      2. |    1   02-05-2021     2    2   2-05-2021      -.5 |
      3. |    1   03-05-2021     1    2   3-05-2021     -1.5 |
      4. |    1   04-05-2021    .5    2   4-05-2021       -3 |
      5. |    1   05-05-2021     3    2   5-05-2021       -2 |
         +---------------------------------------------------+
    Last edited by Andrew Musau; 26 Apr 2024, 05:00.

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      The sum command calculates a running sum, while the -bysort- prefix restricts the calculation to each group.

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input byte firm double r byte mr str9 evendate
      1 1.5 2 "1-05-2021"
      1 2 2 "2-05-2021"
      1 1 2 "3-05-2021"
      1 .5 2 "4-05-2021"
      1 3 2 "5-05-2021"
      end
      
      gen edate= daily(evendate, "DMY"), after(firm)
      format edate %tdD-N-CY
      bys firm (edate): gen wanted= sum(r - mr)
      Res.:

      Code:
      . l, sepby(firm)
      
      +---------------------------------------------------+
      | firm edate r mr evendate wanted |
      |---------------------------------------------------|
      1. | 1 01-05-2021 1.5 2 1-05-2021 -.5 |
      2. | 1 02-05-2021 2 2 2-05-2021 -.5 |
      3. | 1 03-05-2021 1 2 3-05-2021 -1.5 |
      4. | 1 04-05-2021 .5 2 4-05-2021 -3 |
      5. | 1 05-05-2021 3 2 5-05-2021 -2 |
      +---------------------------------------------------+
      Thank you very much

      Comment


      • #4
        Note the correction in #2: It should read "the -sum()- function of generate".

        Comment

        Working...
        X