Announcement

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

  • Creating a sum variable which depends on 2 other variables

    Hello!

    I am currently working on a panel dataset containing, amongst others, the variables "companies", "year" (2010-2018), "sector" (arbitrary 4 digit number), and "net sales". Now,
    I want to generate a new variable, namely, the sum of the net sales for all individual companies in each corresponding sector and the corresponding year.

    I tried to find a command, however, I was unsuccessful.

    Can anyone help me out?

    Thank you in advance!
    Last edited by Sebastian Finke; 02 Apr 2020, 01:17.

  • #2
    Code:
    bysort sector year: egen wanted= total(net_sales)

    Comment


    • #3
      Code:
      help egen 
      
      egen wanted = total(net_sales), by(sector year)

      Comment


      • #4
        Amazing! Thank you, it worked out perfectly!

        Comment

        Working...
        X