Announcement

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

  • counting 1s in each group

    Hi STATALIST,

    I have variables group and order. I want a new variable which is counting 1s in the variable order in each group.

    could you please help me to create the new variable ("wanted-counting 1s in each group")?

    group order wanted-counting 1s in each group
    a 1 1
    a 2
    a 3
    a 1 2
    a 2
    a 3
    a 1 3
    a 2
    a 1 4
    a 2
    a 3
    a 4
    b 1 1
    b 1 2
    b 2
    b 3
    b 1 3
    b 2
    Regards,
    Masoumeh

  • #2
    Code:
    sort group, stable 
    
    by group : gen count1 = sum(order == 1) if order == 1
    where if order == 1 may or may not be what you want.

    Comment

    Working...
    X