Announcement

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

  • Exclude certain observations only in one variable?

    Hello

    Code:
    gen gift_group_test = 0 if gift_total < . & gift_received == 1
    replace gift_group_test = 1 if gift_total > 0 & gift_total < 10000
    replace gift_group_test = 2 if gift_total >= 10000 & gift_total <= 100000
    replace gift_group_test = 3 if gift_total > 100000
    label define gift_group_test  0 "<10K" 1 "10K-100K" 2 "100K+" 
    label val gift_group_test gift_group_test
    I am trying to group observations given the amount of gifts they have received. Yet for some reason in the category 1 ("<10K") I have 2 observations who have not received any gifts, their gift_total = 0.

    No matter what I do I cannot solve the issue, so I was wondering, can I suppress these two observations in a way that I keep them within my data set, but just throw them out of the variable gift_group_test? Is that possible?

  • #2
    Show the two observations in question please.

    Comment


    • #3
      I'll just add that your code could use some improvements, apart from the issue you raise.

      This:
      Code:
      gen gift_group_test = 0 if gift_total < . & gift_received == 1
      Should probably be:
      Code:
      gen gift_group_test = 0 if gift_total == 0
      Note also that any value is smaller than missing, so 'if gift_total < . & gift_received == 1' is redundant: any value exactly equal to 1 (or 0) would be smaller than missing.

      Your code:
      Code:
      gen gift_group_test = 0 if gift_total < . & gift_received == 1
      replace gift_group_test = 1 if gift_total > 0 & gift_total < 10000
      replace gift_group_test = 2 if gift_total >= 10000 & gift_total <= 100000
      replace gift_group_test = 3 if gift_total > 100000
      Could be simplified to:
      Code:
      gen gift_group_test = 0 if gift_total == 0 
      replace gift_group_test = 1 if gift_total > 0 
      replace gift_group_test = 2 if gift_total >= 10000
      replace gift_group_test = 3 if gift_total > 100000 & gift_total !=.
      (again presuming you want the first group o be zero gifts received)

      Also note hat your labels are probably not what you want:
      Code:
      label define gift_group_test  0 "<10K" 1 "10K-100K" 2 "100K+"
      Should probably be:
      Code:
      label define gift_group_test  0 "Zero" 1 "<10K" 2 "10K-100K" 3 "100K+"
      Based on how you define the group numbers


      Comment

      Working...
      X