Announcement

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

  • Sum if/by

    Hello Everyone,

    I have the following dataset:
    bse_mkt_cap date2 ind_num2
    1325.5 02apr1996 10
    185.8 02apr1996 10
    725.57 02apr1996 10
    1325 03apr1996 10
    189 03apr1996 10
    725.60 03apr1996 10
    325.5 02apr1996 11
    135.9 02apr1996 11
    7025.7 02apr1996 11
    325.3 03apr1996 11
    135.9 03apr1996 11
    7025.5 03apr1996 11

    I want to sum the bse_mkt_cap by date and ind_num2 and get daily_mkt_cap.

    For eg, I want the results as following (I manually added the bse_mkt_cap to show how I want the results):
    bse_mkt_cap date2 ind_num2 daily_mkt_cap
    1325.5 02apr1996 10 2236.87
    185.8 02apr1996 10 2236.87
    725.57 02apr1996 10 2236.87
    1325 03apr1996 10 2239.6
    189 03apr1996 10 2239.6
    725.60 03apr1996 10 2239.6
    325.5 02apr1996 11 7487.1
    135.9 02apr1996 11 7487.1
    7025.7 02apr1996 11 7487.1
    325.3 03apr1996 11 7486.7
    135.9 03apr1996 11 7486.7
    7025.5 03apr1996 11 7486.7

    Kindly help with the code.

  • #2
    Code:
    egen daily_mkt_cap = total(bse_mkt_cap), by(date2 ind_num2)

    Comment


    • #3
      Thankyou Øyvind!

      Comment

      Working...
      X