Announcement

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

  • How can I aggregate the sum of a variable only for each subgroup?

    I have here a Steam Dataset which includes individual steam user and their playtimes(overall) and the games they played. I further divided the player in hardcore(=1) and casual player (=0). Overall I want to test how various factors have influence on the overall playtime of the players, but now I want to build 2 regressions, one for hardcore players and one for casual players(because I think that the effect of every factor can differ between those two). But in order to do that, I need the sum of the overall playtime from the 2 subgroups. I tried
    Code:
    egen playtime_type = sum(playtime_sum), by (hightype)
    , but the outcome just doesn't make sense. How can I aggregate the sum of playtime only for each subgroup?

    Here is a example from the dataset

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str17 steamid float(playtime_sum hightype)
    "76561197960265729"    0 0
    "76561197960265730"   45 0
    "76561197960265730"   45 0
    "76561197960265730"   45 0
    "76561197960265733" 1710 0
    end
    Last edited by Xu Ji; 27 Sep 2022, 06:10.

  • #2
    I notice you have several duplicates in there, which will probably cause the sum to go wrong. You can either
    Code:
    duplicates drop steamid, force
    egen playtime_type = sum(playtime_sum), by(hightype)
    to get rid of the duplicates, or you can
    Code:
    egen tag = tag(steamid)
    egen playtime_type = sum(playtime_sum*tag), by(hightype)
    drop tag
    which makes the duplications cease to count.

    Comment


    • #3
      I am sorry I forgot to mention that every row means one game. So ID 7656...30 appears 3 times means there are three games documented.

      Comment


      • #4
        I think it would be useful for you to show what values you expect the variable to take for this sample dataset

        Comment


        • #5
          Cross-posted at https://stackoverflow.com/questions/...-for-subgroups

          Please note our policy on cross-posting, which is that you are asked to tell us about it.

          Comment


          • #6
            Thank you Nick, I will pay attention to that in the future.

            Comment

            Working...
            X