Announcement

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

  • Combine observations by conditions in one dataset

    Hi everyone,

    I need to combine the observations and calculate the sum in my dataset. Please see the example below:
    Year Brand Size Unit Revenue
    1 2010 A 1 100 10000
    2 2010 A 1 200 20000
    3 2010 B 3 100 30000
    4 2011 A 2 100 15000
    5 2011 B 1 100 8000
    6 2011 B 2 200 26000
    7 2011 B 2 200 27000
    8 2012 C 1 100 9000
    9 2012 C 3 100 40000
    10 2012 C 3 300 120000
    And I need to combine the observations within the same year, brand, and size, and then sum up their unit and revenue, respectively, so the result should look at this:
    Year Brand Size Unit Revenue
    1 2010 A 1 300 30000
    2 2010 B 3 100 30000
    3 2011 A 2 100 15000
    4 2011 B 1 100 8000
    5 2011 B 2 400 53000
    6 2012 C 1 100 9000
    7 2012 C 3 400 160000
    How could I do this in Stata? Thank you!


  • #2
    See the collapse command.

    In particular, you could try

    Code:
    collapse (sum) unit revenue, by(year brand size)

    Comment


    • #3
      Originally posted by Hemanshu Kumar View Post
      See the collapse command.

      In particular, you could try

      Code:
      collapse (sum) unit revenue, by(year brand size)
      Hi Hemanshu,

      You code worked perfectly. Thank you so much for your help!

      Comment

      Working...
      X