Announcement

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

  • Finding Market Shares

    Hi all,

    I have a data in the following format. I need to calculate the market share where market share would be simply percentage of sales of the brand in the given year and market. For example, A in the table should be Sales of Brand 1 in year 2000 and market 1 to Total sales in year 2000 and market 1. This should be 56 / (56 + 25). Similarly, B should be (34 / (34+54+43) ). Finally, C should be (47/ (47+43)). Any coding help for such problem is much appreciated.
    Year Market Brand Sales Market Share
    2000 1 1 56 A
    2001 1 1 34 B
    2002 1 1 45
    2001 1 2 54
    2002 1 2 46
    2000 1 3 25
    2001 1 3 43
    2002 1 3 41
    2000 2 1 47 C
    2001 2 1 65
    2002 2 1 62
    2001 2 2 21
    2002 2 2 43
    2000 2 3 43

  • #2
    Code:
    bysort year market: egen tsales=total(sales)
    gen marketshare=sales/tsales*100

    Comment


    • #3
      Muhammad, you may try the following code.

      Code:
      bys year market: egen total_sales = total(sales)
      gen share = sales / total_sales

      Comment


      • #4
        Thank you so much Chen and Fei, that was helpful.

        Comment


        • #5
          Here is a more direct solution. As requested in the FAQ Advice #12, please use dataex .


          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input int year byte(market brand sales)
          2000 1 1 56
          2001 1 1 34
          2002 1 1 45
          2001 1 2 54
          2002 1 2 46
          2000 1 3 25
          2001 1 3 43
          2002 1 3 41
          2000 2 1 47
          2001 2 1 65
          2002 2 1 62
          2001 2 2 21
          2002 2 2 43
          2000 2 3 43
          end
          
          egen wanted = pc(sales), by(year market)
          l, sepby(year market)
          
               +------------------------------------------+
               | year   market   brand   sales     wanted |
               |------------------------------------------|
            1. | 2000        1       1      56    69.1358 |
            2. | 2000        1       3      25    30.8642 |
               |------------------------------------------|
            3. | 2000        2       1      47   52.22222 |
            4. | 2000        2       3      43   47.77778 |
               |------------------------------------------|
            5. | 2001        1       1      34    25.9542 |
            6. | 2001        1       2      54   41.22137 |
            7. | 2001        1       3      43   32.82443 |
               |------------------------------------------|
            8. | 2001        2       1      65    75.5814 |
            9. | 2001        2       2      21    24.4186 |
               |------------------------------------------|
           10. | 2002        1       1      45   34.09091 |
           11. | 2002        1       2      46   34.84848 |
           12. | 2002        1       3      41   31.06061 |
               |------------------------------------------|
           13. | 2002        2       1      62   59.04762 |
           14. | 2002        2       2      43   40.95238 |
               +------------------------------------------+

          Comment

          Working...
          X