Announcement

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

  • new variable based on levels of 2 other variables

    Hi,

    I have the following 2 variables :


    1. tab pdlast

    pdlast | Freq. Percent Cum.
    ------------+-----------------------------------
    1 | 28 1.02 1.02
    1.5 | 9 0.33 1.35
    2 | 252 9.20 10.55
    2.5 | 126 4.60 15.15
    3 | 1,263 46.09 61.24
    3.5 | 231 8.43 69.67
    4 | 429 15.66 85.33
    4.5 | 57 2.08 87.41
    5 | 170 6.20 93.61
    5.5 | 22 0.80 94.42
    6 | 111 4.05 98.47
    6.5 | 1 0.04 98.50
    7 | 23 0.84 99.34
    8 | 7 0.26 99.60
    9 | 10 0.36 99.96
    12 | 1 0.04 100.00
    ------------+-----------------------------------



    2. bop_deepest

    5 | Freq. Percent Cum.
    ------------+-----------------------------------
    0 | 351 87.31 87.31
    1 | 51 12.69 100.00

    ------------+-----------------------------------

    I would like to create a new variable with 2 levels and with the following conditions:

    0 if pdlast is less than 5 and bop_deepest is 0 or 1 OR if pdlast is 5 or 5.5 and bop_deepest ==0

    1
    if pdlast is 5 or 5.5 and bop_deepest ==1 OR if
    pdlast is 6 or higher and bop_deepest is 0 or 1

    Any help would be appreciated.

    Thank you,

    Nikos

  • #2
    Assuming neither pdlast nor bop_deepest has missing values, the following should do what you want.
    Code:
    generate new = .
    replace new = bop_deepest if bop_deepest<.
    replace new = 0 if pdlast<5
    replace new = 1 if pdlast>=6 & pdlast<.

    Comment


    • #3
      Obviously, in post #2 I updated my code to deal with missing values, but neglected to remove the "Assuming" in the first sentence.

      Comment


      • #4
        Thank you William
        BW
        Nikos

        Comment

        Working...
        X