Announcement

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

  • Categorical variable

    How do I generate a categorical variable? Taking the following values: 0 if the household lives beneath the $1 a day poverty line; 1 if the household lives beneath the $2 a day poverty line, but above the $1 line; 2 otherwise. There are two variables poor1 (0 and 1) which describes household beneath $1 a day poverty line and poor2 (0 and 1): which describes household beneath $2 a day poverty line.

    I did the following: gen income_group = 0 if poor1==1
    replace income_group = 1 if poor2==1
    replace income_group = 2 if poor2>1
    replace income_group = 0 if poor1==1

    However, I am not quite sure. What do I do when it says: missing values?

    Any help is highly appreciated!

  • #2
    Code:
    assert inlist(poor1, 0, 1) | missing(poor1)
    assert inlist(poor2, 0, 1) | missing(poor2)
    assert poor2 == 1 if poor1 == 1
    gen income_group = 0 if poor1 == 1
    replace income_group = 1 if poor2 == 1 & poor1 == 0
    replace income_group = 2 if poor2 == 0
    The first two commands verify that poor1 and poor2 are both coded 0/1 (with possible missing values.) The third command verifies that whenever poor1 == 1, then poor2 also == 1. If these aren't true, then these variables are not coded in the way you describe and the proposed code will not produce correct results. The rest of the code creates the variable you want.

    The handling of missing values is complicated. Because of the tautology that if you are below the $1 per day level you are necessarily also below the $2 per day level, we can ignore missing values of poor2 whenever poor1 == 1. So income_group will be missing if poor1 is missing. It will also be missing if poor2 is missing, unless poor1 == 1.

    Comment


    • #3
      You might also try

      Code:
      tab2 poor1 poor2, missing
      That will tell you at a glance whether the poor1 and poor2 coding is correct, and will also help you determine whether your final variable has been coded correctly.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      Stata Version: 17.0 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        Thank you, this has helped me a lot!

        Comment

        Working...
        X