Announcement

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

  • Summing A Financial Data Variable Using Multiple Group Categorisation Variables

    Hi all,

    My apologies if this is a very basic question, but I'm been digging around for ages and am still unable to solve it, so thought I'd ask.

    I have a dataset of payment data, where I want to merge the sum of payments based on the category of payment and the region the payment was sent to. So I effectively have three variables in play.

    1) The amount of the Payment (€)
    2) Type of Payment (Categories)
    3) Region sent to (Name of Region). (All have been recoded to be numerical)

    There are multiple entries for all kinds of payments and regions, and I want to edit to so that I sum all the payments by region and category. So the total of Payment Category Y to Region X, the total of Payment Category Z to Region X, the total of Payment Category Y to Region T etc.

    Again, this might be very basic and I might be missing something obvious, but I have looked for ages and been unable to find an answer.

    Thanks!

  • #2
    As you don't show example data, I am guessing at the names of your variables. But the changes to this code you will need to make should be obvious:
    Code:
    collapse (sum) payment, by(region category)

    Comment


    • #3
      Austin:
      welcome to this forum.
      Do you mean something along the following lines?
      Code:
      . use "https://www.stata-press.com/data/r17/nlswork.dta"
      (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
      
      . bysort idcode grade c_city: egen wanted=total(ln_wage)
      
      . list idcode grade c_city ln_wage if idcode<=2
      
             +------------------------------------+
             | idcode   grade   c_city    ln_wage |
             |------------------------------------|
          1. |      1      12        0   2.462927 |
          2. |      1      12        0   2.536374 |
          3. |      1      12        1   1.777012 |
          4. |      1      12        1   2.551715 |
          5. |      1      12        1   1.778681 |
             |------------------------------------|
          6. |      1      12        1    1.02862 |
          7. |      1      12        1   1.451214 |
          8. |      1      12        1   1.780273 |
          9. |      1      12        1   2.420261 |
         10. |      1      12        1   2.493976 |
             |------------------------------------|
         11. |      1      12        1   2.614172 |
         12. |      1      12        1   1.589977 |
         13. |      2      12        1   1.863417 |
         14. |      2      12        1   1.206198 |
         15. |      2      12        1   1.789367 |
             |------------------------------------|
         16. |      2      12        1   1.726721 |
         17. |      2      12        1   1.726964 |
         18. |      2      12        1   1.832581 |
         19. |      2      12        1    1.84653 |
         20. |      2      12        1    1.68991 |
             |------------------------------------|
         21. |      2      12        1   1.808289 |
         22. |      2      12        1   1.856449 |
         23. |      2      12        1   1.360348 |
         24. |      2      12        1   1.549883 |
             +------------------------------------+
      
      .
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4

        Hi again! This
        Code:
        collapse (sum) payment, by(region category)
        solved it. Thank you both for the response and the help, and for the welcome to the forum! Best, ​​​​​​​Austin

        Comment

        Working...
        X