Announcement

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

  • Combining mi:passive with egen options

    Hi All

    I've just imputed my dataset (in the wide format), and I would like to create a set of passive variables based on the imputed variables. For example I have imputed BMI and I would like to categorise this into normal, overweight & obese:

    Code:
    mi passive: egen cut (bmi), at(24.99, 29.99), gen(bmicat)
    This is obviously not working, can anyone help with the above?

    Also, is there another option besides 'cut' which one can combine with egen when creating categorical variables from continuous ones?

    Thanks!

    /Amal

  • #2
    I don't know much about mi, but your egen call is clearly illegal. By itself it should perhaps be


    Code:
     egen bmicat = cut(bmi) , at(24.99, 29.99)
    although my guess is that will leave most values unclassified.

    I have never understood the appeal of cut(). For example, its default behaviour with end classes is not one I would typically seek.

    Code:
    gen wanted = cond(bmi < 25, 1, cond(bmi < 30, 2, 3)) if bmi < .
    is to my mind completely explicit (although goodness know why BMI is better off binned at all).



    Last edited by Nick Cox; 18 Oct 2019, 09:13.

    Comment


    • #3
      Hi Nick

      Thanks, but unfortunately 'cond' isn't recognised by mi:passive so it did not work. And the first option (as you rightly said) threw away 95% of the BMI values!

      The reason I chose 'cut' is because mi:passive only recognises gen, egen & replace.

      In this case as I have to generate a new categorical variable based on an imputed one, egen seemed to be the only option....

      Comment


      • #4
        But indeed my code uses generate, so what functions it calls should be immaterial.

        Comment


        • #5
          Ahh thanks, it worked this time I had a typo.

          What if I wanted to dichotomous a continuous variable, where 0 was all those with values 0 to 4 and 1 with values 5 to 10?

          I tried:

          Code:
          gen rutcat2 = cond(rutter2all<5, 0)) if rutter2all<.
          For clarity, I'd like to see both categories defined in the code:

          Code:
          gen rutcat2 = cond(rutter2all<5, 0, cond(rutter2all>4, 1)) if rutter2all<.
          But I'm doing something wrong....

          Comment


          • #6
            The verb is dichotomize (or -ise).

            Code:
             
             gen rutcat2 = cond(rutter2all<5, 0)) if rutter2all<.
            Your parentheses aren't matched. You don't have three arguments.


            Code:
             
             gen rutcat2 = cond(rutter2all<5, 0, cond(rutter2all>4, 1)) if rutter2all<.
            Your inner call to cond() doesn't have three arguments either.

            It can be done like this:

            Code:
            gen rutcat2 = inrange(rutteral2all, 5, 10) if inrange(rutter2all, 0, 10)

            or like this

            Code:
            gen rutcat2 = cond(inlist(rutter2all, 0, 1, 2, 3, 4), 0, cond(inlist(rutter2all, 5, 6, 7, 8, 9, 10), 1, .))
            or like this

            Code:
            gen rutcat2 = cond(inrange(rutter2all, 0, 4), 0, cond(inrange(rutter2all, 5, 10), 1, .))
            (with some mild assumptions there that non-integers don't appear)

            and in other ways too.



            Comment

            Working...
            X