Announcement

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

  • #16
    If a variable is equal to 7000 it can't be missing too. Your code produces missing if the input is missing, 0 if it is 7000 and 1 otherwise. This is another way to get that

    Code:
    gen relig = religb != 7000 if religb != .
    except that if you have any of .a to .z you probably want to exclude them too. I would usually go

    Code:
    gen relig = religb != 7000 if religb < .
    for that reason as .a to .z are deemed greater than system missing (.) and the < sign excludes them all.


    Comment


    • #17
      Appreciated Nick Cox. That seems to have fixed the issue. Thank you very much.

      Comment


      • #18
        Hi Statalist.

        I want to generated a dummy variable from a categorical variable with values ranging '0-10'. The range '0-2' is nil to low and '3-10' is mid-high. I note that I have two categorical variables: one relates to responses by husbands and the other by wives(relimp1 - importance for husband, relimp2 - importance for wife):
        Code:
        gen byte imp2 = inrange(relimp1, 3, 10) & inrange(relimp2, 3, 10) & relimp1 < . & relimp2 < .
        However as you can see below, "0" was given when relimp1 or relimp2 were 'missing', so I tried:
        Code:
        gen byte imp4 = 1 if inrange(relimp1, 3, 10) & inrange(relimp2, 3, 10) & relimp1 < . & relimp2 < .
            replace imp4 = 0 if (relimp12 == 1 & relimp22 == 1) | (relimp12 == 1 & inlist(relimp22, 2, 3)) | (inlist(relimp12, 2, 3) & relimp22 == 1)
        which provided "1" when true, "0" when false, and "." when missing - which is what I thought I should get. Based on my reading of https://www.stata.com/support/faqs/d...rue-and-false/ I thought the first piece of code would have given me this outcome.

        Given the first piece of code has considerably more "0" than the second piece of code, I believe I should go with the second piece of code (imp4). Help is appreciated.
        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input long(id p_id) byte(wave relimp1 relimp2 imp2 imp4)
        100006 1000842 10  .  . 0 .
        100006 1000842 11  .  . 0 .
        100006 1000842 12  .  . 0 .
        100006 1000842 13  .  . 0 .
        100006 1000842 14  0  0 0 0
        100006 1000842 15  .  . 0 .
        100006 1000842 16  .  . 0 .
        100006 1000842 17  .  . 0 .
        100006 1000842 18  0  0 0 0
        100008  100009  1  .  . 0 .
        100008  100009  2  .  . 0 .
        100008  100009  3  .  . 0 .
        100008  100009  4  5  6 1 1
        100008  100009  5  .  . 0 .
        100008  100009  6  .  . 0 .
        100008  100009  7  .  5 0 .
        100023  100024  4 10 10 1 1
        100023  100024  5  .  . 0 .
        100023  100024  6  .  . 0 .
        100023  100024  7 10 10 1 1
        100023  100024  8  .  . 0 .
        100023  100024  9  .  . 0 .
        100023  100024 10 10 10 1 1
        100023  100024 11  .  . 0 .
        100023  100024 12  .  . 0 .
        100023  100024 13  .  . 0 .
        100023  100024 14 10 10 1 1
        100023  100024 15  .  . 0 .
        100023  100024 16  .  . 0 .
        100023  100024 17  .  . 0 .
        100023  100024 18 10 10 1 1
        I understand that
        Code:
        ! missing(relimp1, relimp2)
        is the same as
        Code:
        relimp1 < . & relimp2 < .
        Stata 15.1.
        Last edited by Chris Boulis; 28 Sep 2020, 06:20.

        Comment

        Working...
        X