Announcement

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

  • Generate new variable by groups

    Hello
    I have one problem, I need to create a new variable:

    I have a dataset with the id of groups of students, the name of each integrate and if the student is female (=1) or not (=0)

    I need to know two things:
    1. groups with at least one women in each group and
    2. groups with only formed by women

    You have any ideas how can I do that?

  • #2
    Code:
    clear
    input group female
    1 0
    1 0
    1 0
    1 0
    2 0
    2 1
    2 0
    2 0
    3 1
    3 1
    3 1
    end
    
    bysort group: gen sum = sum(female)
    list, sepby(group)
    by     group: replace sum = sum[_N]
    list, sepby(group)
    
    by     group: gen somefemale = sum > 0 & sum < _N
    by     group: gen allfemale  = sum == _N
    list, sepby(group)
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      See also https://www.stata.com/support/faqs/d...ing/index.html

      Comment

      Working...
      X