Announcement

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

  • Use of lincom for 3-way interaction of categorical variables

    Hi everyone,

    I am trying to determine the OR of smoking (binary) among different groups accounting for a 3 way interaction between race, sex and education.
    race=0 if white and =1 if black
    sex=0 if female and 1 if man
    education =0 none 1= High school 2= college

    My model is : logistic smokes race sex education i.sex##i.race##i.education

    I am interest in describing how education level protects differently men and women depending on their race. Getting confused and unable to test my sintaxis with my online reads, I would really appreciate if you could check my lincom models.

    Thank you!!!!



    Gender differences within same race

    1. white men vs white women with no education
    lincom 1.sex, or
    2.black men vs black women with no education
    lincom 1.sex + 1.sex#1.race , or
    3. black men vs black women with High school
    lincom 1.sex + 1.sex#1.race +1.race#1.education + 1.sex#1.race#1.education, or

    Race differences within same gender
    4. white women vs black women with no education
    lincom 1.race , or
    5. white women vs black women with high school
    lincom 1.race +1.race#1.education , or

    6. black men vs with men without education
    lincom 1.sex + 1.race + 1.sex#1.race , or

    7. black men vs with men with High school
    lincom 1.sex + 1.race + 1.sex#1.race 1.sex#1.race#1.education, or


    thanks!

  • #2
    Even people who have done this sort of thing regularly for years find these calculations confusing when you come to three-way interactions.

    Use the -margins- command instead of -lincom-. It automates the algebra for you, and also can adjust the results for any other variables that might be in your model (apparently not an issue for the present). It's a bit complicated to learn, but Richard Williams has a great introduction to it at http://www.stata-journal.com/sjpdf.h...iclenum=st0260.

    Comment


    • #3
      Thank you very much! I have tried to understand the margins already but I have found it challenging and due my coming deadline I am leaning towards using lincom because I feel more comfortable about it. I agree it is way less efficient.In nay case I am reading the introduction you shared , thank you!

      Comment


      • #4
        There is definitely a steep learning curve for using -margins-. But in the end, it will save you tons of time, and, more importantly, it will prevent numerous errors.

        Comment


        • #5
          Thanks Clyde, I have read all the documentation and end up doing this:

          . margins i.race2 i.sex education4 i.sex##i.race2##i.education4 , expression(exp(predict(xb)))

          instead of the lincom, then I understand I need to divide them to get OR comparing right?

          sex#race2#education4 |
          Female#White#<hs | 10.03216 2.075099 4.83 0.000 5.965043 14.09928
          Female#White#hs/vocational | 8.249569 1.93184 4.27 0.000 4.463232 12.03591
          Female#White#some college/college 6.810894 1.579885 4.31 0.000 3.714376 9.907413
          Female#Black#<hs | 11.88815 2.962277 4.01 0.000 6.082194 17.69411
          Female#Black#hs/vocational | 12.65079 3.192493 3.96 0.000 6.393619 18.90796
          Female#Black#some college/college | 9.435443 2.352693 4.01 0.000 4.82425 14.04664
          Male#White#<hs | 13.48761 3.447576 3.91 0.000 6.730482 20.24473
          Male#White#hs/vocational | 13.18545 3.442184 3.83 0.000 6.438895 19.93201
          Male#White#some college/college | 11.1455 2.7337 4.08 0.000 5.787548 16.50346
          Male#Black#<hs | 9.79239 2.618364 3.74 0.000 4.660491 14.92429
          Male#Black#hs/vocational | 8.597808 2.745572 3.13 0.002 3.216586 13.97903
          Male#Black#some college/college | 15.03348 5.048197 2.98 0.003 5.1392 24.92777


          For example, the lincom where I wanted to calculate:
          7. black men vs with men with High school
          lincom 1.sex + 1.race + 1.sex#1.race 1.sex#1.race#1.education, or

          would be just : 8.597808 / 13.18545 right? OR= 0.65

          I have also tried the atmeans but still unsure of how to use it.


          thank you very much, Paloma

          Comment


          • #6
            Yes, your calculation of that odds ratio is correct.

            As for -atmeans-, here's an explanation. Ordinarily, when -margins- performs its calculations, it sets the variables specified in the varlist of the -margins- command to particular values. For example, the -margin- for Male#Black#some college/college is calculated by setting sex to Male, race to Black, and education to some college/college in every observation of the data set, and then applying -predict- (and, in your case, then exponentiating the result), and then averaging those results over the sample. What does it do with the unmentioned variable, smoking? It leaves it as is in the original data. So while the calculation has fixed values of sex, race, and education, the value of smoking is left to vary in whatever way it does in your estimation sample.

            If you specify -atmeans-, -margins- proceeds differently. It calculates the mean values in the estimation sample of all variables not included in the varlist: in your case this boils down to the one unmentioned variable, smoking. Now, in addition to setting the values of sex, race, and education to the values corresponding to the particular margin, it sets the value of smoking to its estimation-sample-mean value in every observation, and then applies -predict- (and then, in your situation, exponentiates the result) and then averages those results over the sample.

            Putting it in a more summary form, without -atmeans-, the margins calculated are adjusted to the overall distribution of the unmentioned variables in the estimation sample. With -atmeans-, the margins are calculated for a hypothetical entity whose value for each unmentioned variable is that variable's estimation sample mean. Without -atmeans-, you are adjusting to the sample distribution overall; with -atmeans- you are adjusting to a (most likely hypothetical) unit of observation (person, in your case) who is exactly average on every attribute.

            When the unmentioned variable is a dichotomy, as in your case, the interpretation of the -atmeans- results is a bit problematic. Say 2/3 of your observed people are non-smokers and 1/3 of them smoke. Then with -atmeans- you are producing odds that apply to a person who is 1/3 of a smoker, whatever that means.

            Comment


            • #7
              Thank you very much for that detailed explanation. I do have more covariates, all of them categorical so I will keep it without atmeans option for this example. Thank you!

              Comment


              • #8
                I am facing another difficulty, the margins does not facilitate me the CI of the OR that I calculate, is there anyway to get it? Thank you!!

                Comment


                • #9
                  In that case, then you should revert to the various -lincom- commands you outlined in your original post. They appear to be correct for the contrasts you associated them with.

                  I don't believe you can get those directly out of -margns-. If you were interested in these effects in the probability metric, rather than the odds ratio metric, these results could be obtained from -margins- with the -dydx()- option specified, but that will not help you here.

                  Comment


                  • #10
                    I think the following contrast is missing a term:

                    3. black men vs black women with High school
                    lincom 1.sex + 1.sex#1.race +1.race#1.education + 1.sex#1.education + 1.sex#1.race#1.education, or

                    And likewise for the 7th contrast.

                    Comment


                    • #11
                      Leonardo is right. The 1.sex#1.education terms need to be included.

                      Comment


                      • #12
                        Thank you, also in the

                        7. black male vs white males with HS
                        lincom 1.sex + 1.race + 1.sex#1.race + 1.sex#1.race#1.education4, or

                        I should remove the 1.sex isnt it?

                        so the right expression would be:

                        7. black male vs white males with HS
                        lincom 1.race + 1.sex#1.race + 1.sex#1.education+ 1.sex#1.race#1.education4, or

                        right?

                        Thank you again!
                        Last edited by Paloma Navas; 15 Aug 2016, 12:39.

                        Comment


                        • #13
                          I have been checking the results comparing with the margins and it seems this is the closest.
                          7. black male vs white males with HS
                          lincom 1.race + 1.sex#1.race + 1.race#1.education4 +1.sex#1.race#1.education4, or

                          Comment

                          Working...
                          X