Announcement

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

  • How to calculate the team size?

    I have a dataset as below. There are two columns, one is the team ID, the other is the team member ID. I want to create a column to represent the team size. In other words, the number of unique member ID in each team. Does anyone know how to do it?

    Code:
    cls
    clear all
    input team member
    1    1
    1    1
    1    1
    1    2
    1    2
    1    2
    1    3
    1    3
    1    3
    1    4
    1    4
    1    4
    2    5
    2    5
    2    6
    2    6
    2    6
    2    7
    3    9
    3    9
    3    10
    3    10
    end
    What I would like to have is:

    Code:
    input team member size
    1    1    4
    1    1    4
    1    1    4
    1    2    4
    1    2    4
    1    2    4
    1    3    4
    1    3    4
    1    3    4
    1    4    4
    1    4    4
    1    4    4
    2    5    3
    2    5    3
    2    6    3
    2    6    3
    2    6    3
    2    7    3
    3    9    2
    3    9    2
    3    10    2
    3    10    2
    end

  • #2
    This may help
    Code:
    bysort team member:gen flag=(_n==1)
    bysort team :egen size=sum(flag)

    Comment

    Working...
    X