Announcement

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

  • Combining Duplicates

    Hi,

    I have observations on students and would like to combine duplicate students together. For example,
    class name attendance quiz_mean final exam1
    bio101 AMAL .037 . . .
    bio101 AMAL . 0 0 0
    bio110 GABE . .73 .75 .53
    bio110 GABE .96 . . .
    I would like it to look like this:
    class name attendance quiz_mean final exam1
    bio101 AMAL .037 0 0 0
    bio110 GABE .96 .73 .75 .53
    I tried using:
    Code:
    replace quiz_mean = 0 if quiz_mean == . & name = "AMAL"
    and it didn't work.

    Any help is appreciated!

    Thanks

  • #2
    Welcome to Statalist. In future please use dataex to post data set that can be directly read into Stata. It'd save users here some time if they wish to test the code. Read the FAQ for more info (section 12).

    Code:
    clear
    input str10 class str10     name     attendance     quiz_mean     final     exam1
    bio101     AMAL     .037     .     .     .
    bio101     AMAL     .     0     0     0
    bio110     GABE     .     .73     .75     .53
    bio110     GABE     .96     .     .     .
    end
    
    collapse (mean) attendance-exam1, by(class name)
    list
    Results:

    Code:
         +-----------------------------------------------------+
         |  class   name   attend~e   quiz_m~n   final   exam1 |
         |-----------------------------------------------------|
      1. | bio101   AMAL       .037          0       0       0 |
      2. | bio110   GABE        .96        .73     .75     .53 |
         +-----------------------------------------------------+

    Comment

    Working...
    X