Announcement

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

  • Merging variables

    Hi everyone,

    I have 4 binary variables:
    #1. Tested for HIV during antenatal care (coded as 0/1)
    #2. Got results of HIV test done during antenatal care (coded as 0/1)
    #3. Tested for HIV at the time of delivery (coded as 0/1)

    #4. Got results of HIV test done at the time of delivery (coded as 0/1)

    I would like to combine these 4 variables into a single binary outcome variable, which is defined as "Got tested for HIV during antenatal care AND/OR at the time of delivery AND knew the test results". I have tried using "replace var =...... if)", but I didn't work as desired. May anyone here help me please? Thank you!

  • #2
    Code:
    gen wanted = 0
    replace wanted = 1 if var2==1 | var4==1
    With the idea being that results cannot be gotten when no test was performed. So you may leave out your variables 1 and 3 from your logic.

    Comment


    • #3
      Hi Jorrit,

      I tried your code; and it worked like magic!! I deeply deeply appreciate it!!!

      Comment


      • #4
        Hi,

        My apologies if these simple topics below have been covered here before.

        I am actually having a hard time doing the following things:

        1. I would like to create a composite variable out of 4 DHS binary variables (0=No, 1=Yes): #1: HIV can be transmitted during pregnancy; #2: HIV can be transmitted during breastfeeding; #3: HIV can be transmitted during delivery; #4: Knew that there is special drugs to avoid HIV transmission.

        --> I would like to code my new composite variable as: High PMTCT knowledge (1= having answered YES to 3-4 indicators) vs Low PMTCT knowledge (0= having answered YES to only 1-2 indicators). May anyone here help me with coding please? I greatly appreciate it!


        2. A lot of my independent variables have multi categories. Therefore, I ended up creating many dummies variables (0 is the common reference/comparison group for each dummy variable). However, in the logistic regression, STATA omitted ALL of these dummy variables due to collinearity. Do you have any advice on the issue? Thank you!

        Comment


        • #5
          Hi Phirom,

          Many thanks for your queries

          1. You can use egen command to generate a sum of the 4 variables as long as they are dummies(0/1). Afterwards, recode the new variable (with values 0 - 4) based on your cut-offs.

          2. Why can't you use the i. option rather than the many dummies. For instance i. group and then maybe look at the marginal effects?

          Hope it helps.

          Best,
          Stephen.

          Comment


          • #6
            Hi Stephen,

            I tried egen newvar = rowtotal(v1 v2 v3 v4). This works perfectly!

            I also tried i.variable instead of using dummy variables. STATA didn't omit anything this time! this way is much more efficient!

            I greatly appreciate your help!

            Best
            Phirom

            Comment


            • #7
              I am glad it helped. Just be careful in how you interpret the coefficients or marginal effects for your factor(categorical) variables

              Comment


              • #8
                Hi Stephen,

                When using dummy variables, I am clear that all of them have a common reference group. For example: Primary education vs No education, Secondary vs No education, University vs No education. So it is relatively easy to interpret each coefficient or OR.

                However, when using i.education, can I interpret each coefficient or OR the same way as in the above example? Or is it Primary vs No education, Secondary vs Primary, and University vs Secondary?

                I greatly appreciate your clarifications.

                Best
                Phirom

                Comment


                • #9
                  It would still be the same. When you use i.var, Stata essentially creates your dummy variables for you. And coefficients would all be relative to the base level, which is the level that Stata omits.

                  Comment


                  • #10
                    Hi Stephen,

                    OK i got it! Again, I greatly appreciate your help!

                    Best
                    Phirom

                    Comment


                    • #11
                      Jorrit Gosens is absolutely right. The coefficients are relative to the base level.

                      Comment

                      Working...
                      X