Announcement

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

  • Merging two continuous variables in the same dataset

    Hi,

    I have two variables: 1) age of initiating cigarette use with values from 10-23 and 2) age of initiating hookah use with values from 11-19. Also, these variables are not mutually exclusive and so people could have used both products at different ages. For example, a person could have first-tried a cigarette at 10 years and hookah at 13. I want to combine these variables so that I can create a new variable on age of initiating tobacco substances with values that reflect both variables. I therefore, do not want the variables to simply add up the values. I want the variable to show the lowest age of initiation for each age.


    ex.

    ageofciguse ageofhookahuse
    16 15
    15 16
    10 17
    12 22
    11 11
    14 19
    15 16
    19 18
    16 14

    Ideally, I would like to create a new variable

    ageoftobaccouse
    15
    15
    10
    12
    11
    14
    15
    18
    14

    Next, how can I do this for more than two variables?

  • #2
    Code:
    generate newvar = min(oldvar1, oldvar2, ...)
    Perhaps you need to think about missing values.

    Best
    Daniel

    Comment


    • #3
      Is there a way to skip missing values from the min, and count only numeric values?

      Comment


      • #4
        I do not understand what you mean by "skip missing values"; it seems that min() does that by default

        Code:
        . display min(42,., 73)
        42
        Also, see egen's rowmin() function.

        Best
        Daniel

        Comment

        Working...
        X