Announcement

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

  • Observations in new variable that shouldn't be included

    Hello, I am trying to make a new variable with the following command

    Code:
    gen gift_group_test = 0 if gift_total < . & gift_received == 1
    replace gift_group_test = 0 if gift_total > 0 & gift_total < 10000
    replace gift_group_test = 1 if gift_total >= 10000 & gift_total < 100000
    replace gift_group_test = 2 if gift_total > 100000
    label define gift_group_test  0 "<10K" 1 "10k-100K" 2 "100K+"
    Basically I want to order gifts people have received into 3 groups, below 10k, up to 100k and over 100k. I want to exclude any observations where the person received 0. However, for some reason certain observations are included where the gift received = 0. I thought I would exclude this via the set up. Gift_received == 1 means that the person states they have received a gift. Any idea why I have certain where gifts are == 0? Even if the person says they received a gift and then states the amount is = 0, shouldn't I still be able to exclude that observation by saying gift_total needs to be larger than 0 and smaller than 10k if it wants to be in group 0?

  • #2
    Oscar:
    at a very first glance, it may depend on the way you coded people who gift was=0. If they are coded as:
    [CODE][
    gift_received == 1 /CODE]

    it may explain what you experienced:
    Code:
    . set obs 6
    
    
    . g gift_total=. in 1
    
    
    . replace gift_total=0 in 2
    
    
    . replace gift_total=1000 in 3
    
    
    . replace gift_total=100 in 4
    
    
    . replace gift_total=100000 in 5
    
    
    . replace gift_total=200000 in 6
    
    
    . g gift_received=1 if gift_total!=.
    
    
    . gen gift_group_test = 0 if gift_total < . & gift_received==1
    
    
    . replace gift_group_test = 0 if gift_total > 0 & gift_total < 10000 & gift_received==1
    
    
    . replace gift_group_test = 1 if gift_total >= 10000 & gift_total < 100000 & gift_received==1
    
    
    . replace gift_group_test = 2 if gift_total > 100000 & gift_received==1
    
    
    . label define gift_group_test  0 "<10K" 1 "10k-100K" 2 "100K+"
    
    . label val gift_group_test gift_group_test
    
    . list
    
        +--------------------------------+
         | gift_t~l   gift_r~d   gift_g~t |
         |--------------------------------|
      1. |        .          .          . |
      2. |        0          1       <10K |
      3. |     1000          1       <10K |
      4. |      100          1       <10K |
      5. |   100000          1       <10K |
         |--------------------------------|
      6. |   200000          1      100K+ |
         +--------------------------------+
    
    .
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment

    Working...
    X