Announcement

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

  • interaction effect logistic regression

    Dear Stata users,
    I am working on a paper that includes a logistic regression (logistics command for OR, vce(cluster Country)). A reviewer suggested to include an interaction effect which I did with the following command:

    margins, dydx(VAR!) at(VAR2=(1(1)3))

    initiator has 4 categories, but I want to include the fourth because it has only 2 cases. I'm not sure how to describe that in the justification for the reviewer and I'm not sure if I run into any fundamental problems I'm not thinking about att the moment. Any help or a literature suggestions about a similar case is appreciated.

    Best Anna

  • #2
    Anna:
    welcome to this forum.
    Without further details/example/excerpt about your data (see -help dataex-) it is difficult (for me, at least) to reply positively.
    That said, if part of your query deals with choosing the reference category for categorical variables, you can take a look at -help fvvarlist-.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you Carlo! Thank you very much for you quick reply. I hope this is the correct format, I have never used the dataex command before, but other posts here look similar, thus I hope it is correct.
      The interaction term is between initiator and CSO but one category in initiator has only 3 observations and thus STATA runs into problems: the output has 1 in OR for this category and "empty" for SE. Thus I used the following command margins, dydx(CSO) at(initiator=(1(1)3)) to show only the first three categories of this variable. My question is, whether I run into problems, when I report these three and mention in the text, that there were too few observations for the fourth category?
      Thanks again!
      Anna


      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input byte SUCFAI float initiator byte RIGLO double FHI byte(AGE ParlSemi) double ENPP byte(YSA specialbody CSO)
      1 2 3   5  1 1 3.26  1 0 1
      0 1 3   6  2 1 3.26  2 0 .
      1 2 3   6  2 1 3.26  2 0 .
      1 2 3   6 10 1 1.95 20 0 1
      0 1 3   3 11 0 7.17 11 1 .
      1 1 3 3.5 14 0 7.67 14 1 1
      0 1 3 2.5  1 1 2.41  1 0 1
      0 1 3   2  2 1 2.41  2 0 1
      0 1 3   2  2 1 2.41  2 0 1
      0 1 3   2  2 1 2.41  2 0 1
      0 1 3   2  3 1 2.73  3 0 1
      0 1 3   2  3 1 2.73  3 0 1
      0 1 3   2 10 1 2.92 10 0 1
      1 1 3 1.5 12 1 2.92 12 0 1
      1 1 3 1.5 14 1  4.8 14 0 .
      1 1 3 1.5 15 1  4.8 15 0 .
      1 1 3 1.5 16 1  4.8 16 0 1
      0 1 3 1.5 16 1  4.8 16 0 1
      0 1 3   2 18 1 3.34 18 0 1
      0 1 3   2 20 1 3.34 20 0 1
      1 2 3   4  7 1 2.07  7 0 .
      1 3 3   4  9 1 2.07  9 0 1
      1 3 3 2.5 10 1 4.01 10 0 .
      1 1 3   2 11 1 4.01 11 0 .
      1 1 3 1.5 20 1 3.07 20 0 .
      0 3 3 1.5 21 1 2.59 21 0 .
      0 1 3 1.5 23 1 2.59 23 0 .
      1 4 3 1.5 23 1 2.59 23 0 0
      0 1 6 1.5  0 0  4.8  0 0 1
      0 1 6 1.5  0 0  4.8  0 0 1
      0 1 6 1.5  1 0  4.8  1 0 1
      0 1 6 1.5  2 0  4.8  2 0 0
      0 1 6 1.5  3 0 4.15  3 0 1
      0 1 6 1.5  3 0 4.15  3 0 1
      0 1 6 1.5  3 0 4.15  3 0 1
      0 1 6 1.5  3 0 4.15  3 0 1
      1 3 6 1.5  4 0 4.15  4 0 1
      0 1 6 1.5  4 0 4.15  4 0 1
      0 1 6 1.5  4 0 4.15  4 0 1
      1 1 6 1.5  5 0 3.71  5 0 0
      0 1 6 1.5  5 0 3.71  5 0 1
      0 1 6 1.5  5 0 3.71  5 0 1
      0 1 6 1.5  5 0 3.71  5 0 1
      0 1 6 1.5  6 0 3.71  6 0 1
      0 3 6 1.5  6 0 3.71  6 0 1
      0 3 6 1.5  6 0 3.71  6 0 1
      0 3 6 1.5  6 0 3.71  6 0 .
      0 1 6 1.5  7 0 3.71  7 0 1
      1 3 6 1.5  7 0 3.71  7 0 1
      0 3 6 1.5  7 0 3.71  7 0 1
      0 3 6 1.5  7 0 3.71  7 0 1
      0 1 6 1.5  8 0 3.71  8 0 1
      0 1 6 1.5  8 0 3.71  8 0 1
      0 1 6 1.5  8 0 3.71  8 0 1
      0 1 6 1.5  8 0 3.71  8 0 1
      1 3 6 1.5  8 0 3.71  8 0 1
      0 3 6 1.5  8 0 3.71  8 0 1
      1 3 6 1.5  8 0 3.71  8 0 .
      0 3 6 1.5  8 0 3.71  8 0 .
      1 1 6 1.5  9 0 3.67  9 0 1
      0 1 6 1.5  9 0 3.67  9 0 1
      0 1 6 1.5  9 0 3.67  9 0 1
      0 1 6 1.5  9 0 3.67  9 0 1
      0 1 6 1.5  9 0 3.67  9 0 1
      0 1 6 1.5 10 0 3.67 10 0 1
      0 1 6 1.5 10 0 3.67 10 0 1
      0 3 6 1.5 10 0 3.67 10 0 0
      0 3 6 1.5 10 0 3.67 10 0 1
      0 3 6 1.5 10 0 3.67 10 0 1
      0 1 6   1 12 0 3.67 12 0 1
      0 1 6   1 12 0 3.67 12 0 1
      0 3 6   1 12 0 3.67 12 0 1
      0 1 6   1 13 0  3.1 13 0 1
      0 1 6   1 14 0  3.1 14 0 1
      0 1 6   1 14 0  3.1 14 0 1
      0 1 6   1 14 0  3.1 14 0 1
      0 1 6   1 14 0  3.1 14 0 1
      0 1 6   1 14 0  3.1 14 0 1
      0 1 6   1 14 0  3.1 14 0 1
      1 1 6   1 16 0  3.1 16 0 1
      0 1 6   1 16 0  3.1 16 0 1
      0 1 6   1 16 0  3.1 16 0 1
      0 1 6   1 16 0  3.1 16 0 1
      0 1 6   1 16 0  3.1 16 0 1
      0 1 6   1 16 0  3.1 16 0 1
      0 3 6   1 16 0  3.1 16 0 1
      0 1 6   1 17 0 4.51 17 0 1
      0 1 6   1 17 0 4.51 17 0 1
      0 1 6   1 17 0 4.51 17 0 1
      0 1 6   1 18 0 4.51 18 0 1
      0 1 6   1 18 0 4.51 18 0 1
      0 1 6   1 18 0 4.51 18 0 1
      0 3 6   1 18 0 4.51 18 0 1
      0 1 6   1 19 1 4.51 19 0 1
      0 1 6   1 19 1 4.51 19 0 1
      0 1 6   1 19 1 4.51 19 0 1
      0 1 6   1 19 1 4.51 19 0 1
      1 3 6   1 19 1 4.51 19 0 1
      0 3 6   1 19 1 4.51 19 0 1
      0 3 6   1 19 1 4.51 19 0 1
      end





      Comment


      • #4
        I cannot provide an example with ‘my’ Stata now. But you may also think about something like:
        margins var1#var2 if var2 !=4
        Best regards,

        Marcos

        Comment


        • #5
          Anna:
          thanks for your data excerpt...but the code of your regression seems missing!
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment


          • #6
            Carlo, sorry! I thought the information about the command logistics was sufficient. Her is the code:
            logistic SUCFAI RIGLO FHI ENPP specialbody ParlSemi AGE i.initiator##CSO , vce(cluster Country)
            estat gof
            lfit, group(10) table
            estat class
            lroc

            Comment


            • #7
              Anna:
              sadly:
              Code:
              . logistic SUCFAI RIGLO FHI ENPP specialbody ParlSemi AGE i.initiator##CSO , vce(cluster Country)
              variable Country not found
              r(111);
              Kind regards,
              Carlo
              (Stata 19.0)

              Comment


              • #8
                I hope it will work now! I'm sorry about the back and forth...
                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input byte SUCFAI float initiator byte RIGLO double FHI byte(AGE ParlSemi) double ENPP byte(YSA specialbody) str3 Country byte(CSO EU)
                1 2 3   5  1 1 3.26  1 0 "BEL" 1 0
                0 1 3   6  2 1 3.26  2 0 "BEL" . 0
                1 2 3   6  2 1 3.26  2 0 "BEL" . 0
                1 2 3   6 10 1 1.95 20 0 "BEL" 1 0
                0 1 3   3 11 0 7.17 11 1 "BOS" . 0
                1 1 3 3.5 14 0 7.67 14 1 "BOS" 1 0
                0 1 3 2.5  1 1 2.41  1 0 "BUL" 1 0
                0 1 3   2  2 1 2.41  2 0 "BUL" 1 0
                0 1 3   2  2 1 2.41  2 0 "BUL" 1 0
                0 1 3   2  2 1 2.41  2 0 "BUL" 1 0
                0 1 3   2  3 1 2.73  3 0 "BUL" 1 0
                0 1 3   2  3 1 2.73  3 0 "BUL" 1 0
                0 1 3   2 10 1 2.92 10 0 "BUL" 1 0
                1 1 3 1.5 12 1 2.92 12 0 "BUL" 1 0
                1 1 3 1.5 14 1  4.8 14 0 "BUL" . 1
                1 1 3 1.5 15 1  4.8 15 0 "BUL" . 1
                1 1 3 1.5 16 1  4.8 16 0 "BUL" 1 1
                0 1 3 1.5 16 1  4.8 16 0 "BUL" 1 1
                0 1 3   2 18 1 3.34 18 0 "BUL" 1 0
                0 1 3   2 20 1 3.34 20 0 "BUL" 1 0
                1 2 3   4  7 1 2.07  7 0 "CRO" . 0
                1 3 3   4  9 1 2.07  9 0 "CRO" 1 0
                1 3 3 2.5 10 1 4.01 10 0 "CRO" . 0
                1 1 3   2 11 1 4.01 11 0 "CRO" . 0
                1 1 3 1.5 20 1 3.07 20 0 "CRO" . 1
                0 3 3 1.5 21 1 2.59 21 0 "CRO" . 1
                0 1 3 1.5 23 1 2.59 23 0 "CRO" . 1
                1 4 3 1.5 23 1 2.59 23 0 "CRO" 0 1
                0 1 6 1.5  0 0  4.8  0 0 "CZE" 1 0
                0 1 6 1.5  0 0  4.8  0 0 "CZE" 1 0
                0 1 6 1.5  1 0  4.8  1 0 "CZE" 1 0
                0 1 6 1.5  2 0  4.8  2 0 "CZE" 0 0
                0 1 6 1.5  3 0 4.15  3 0 "CZE" 1 0
                0 1 6 1.5  3 0 4.15  3 0 "CZE" 1 0
                0 1 6 1.5  3 0 4.15  3 0 "CZE" 1 0
                0 1 6 1.5  3 0 4.15  3 0 "CZE" 1 0
                1 3 6 1.5  4 0 4.15  4 0 "CZE" 1 0
                0 1 6 1.5  4 0 4.15  4 0 "CZE" 1 0
                0 1 6 1.5  4 0 4.15  4 0 "CZE" 1 0
                1 1 6 1.5  5 0 3.71  5 0 "CZE" 0 0
                0 1 6 1.5  5 0 3.71  5 0 "CZE" 1 0
                0 1 6 1.5  5 0 3.71  5 0 "CZE" 1 0
                0 1 6 1.5  5 0 3.71  5 0 "CZE" 1 0
                0 1 6 1.5  6 0 3.71  6 0 "CZE" 1 1
                0 3 6 1.5  6 0 3.71  6 0 "CZE" 1 1
                0 3 6 1.5  6 0 3.71  6 0 "CZE" 1 1
                0 3 6 1.5  6 0 3.71  6 0 "CZE" . 1
                0 1 6 1.5  7 0 3.71  7 0 "CZE" 1 1
                1 3 6 1.5  7 0 3.71  7 0 "CZE" 1 1
                0 3 6 1.5  7 0 3.71  7 0 "CZE" 1 1
                0 3 6 1.5  7 0 3.71  7 0 "CZE" 1 1
                0 1 6 1.5  8 0 3.71  8 0 "CZE" 1 1
                0 1 6 1.5  8 0 3.71  8 0 "CZE" 1 1
                0 1 6 1.5  8 0 3.71  8 0 "CZE" 1 1
                0 1 6 1.5  8 0 3.71  8 0 "CZE" 1 1
                1 3 6 1.5  8 0 3.71  8 0 "CZE" 1 1
                0 3 6 1.5  8 0 3.71  8 0 "CZE" 1 1
                1 3 6 1.5  8 0 3.71  8 0 "CZE" . 1
                0 3 6 1.5  8 0 3.71  8 0 "CZE" . 1
                1 1 6 1.5  9 0 3.67  9 0 "CZE" 1 1
                0 1 6 1.5  9 0 3.67  9 0 "CZE" 1 1
                0 1 6 1.5  9 0 3.67  9 0 "CZE" 1 1
                0 1 6 1.5  9 0 3.67  9 0 "CZE" 1 1
                0 1 6 1.5  9 0 3.67  9 0 "CZE" 1 1
                0 1 6 1.5 10 0 3.67 10 0 "CZE" 1 1
                0 1 6 1.5 10 0 3.67 10 0 "CZE" 1 1
                0 3 6 1.5 10 0 3.67 10 0 "CZE" 0 1
                0 3 6 1.5 10 0 3.67 10 0 "CZE" 1 1
                0 3 6 1.5 10 0 3.67 10 0 "CZE" 1 1
                0 1 6   1 12 0 3.67 12 0 "CZE" 1 0
                0 1 6   1 12 0 3.67 12 0 "CZE" 1 0
                0 3 6   1 12 0 3.67 12 0 "CZE" 1 0
                0 1 6   1 13 0  3.1 13 0 "CZE" 1 0
                0 1 6   1 14 0  3.1 14 0 "CZE" 1 0
                0 1 6   1 14 0  3.1 14 0 "CZE" 1 0
                0 1 6   1 14 0  3.1 14 0 "CZE" 1 0
                0 1 6   1 14 0  3.1 14 0 "CZE" 1 0
                0 1 6   1 14 0  3.1 14 0 "CZE" 1 0
                0 1 6   1 14 0  3.1 14 0 "CZE" 1 0
                1 1 6   1 16 0  3.1 16 0 "CZE" 1 0
                0 1 6   1 16 0  3.1 16 0 "CZE" 1 0
                0 1 6   1 16 0  3.1 16 0 "CZE" 1 0
                0 1 6   1 16 0  3.1 16 0 "CZE" 1 0
                0 1 6   1 16 0  3.1 16 0 "CZE" 1 0
                0 1 6   1 16 0  3.1 16 0 "CZE" 1 0
                0 3 6   1 16 0  3.1 16 0 "CZE" 1 0
                0 1 6   1 17 0 4.51 17 0 "CZE" 1 0
                0 1 6   1 17 0 4.51 17 0 "CZE" 1 0
                0 1 6   1 17 0 4.51 17 0 "CZE" 1 0
                0 1 6   1 18 0 4.51 18 0 "CZE" 1 0
                0 1 6   1 18 0 4.51 18 0 "CZE" 1 0
                0 1 6   1 18 0 4.51 18 0 "CZE" 1 0
                0 3 6   1 18 0 4.51 18 0 "CZE" 1 0
                0 1 6   1 19 1 4.51 19 0 "CZE" 1 0
                0 1 6   1 19 1 4.51 19 0 "CZE" 1 0
                0 1 6   1 19 1 4.51 19 0 "CZE" 1 0
                0 1 6   1 19 1 4.51 19 0 "CZE" 1 0
                1 3 6   1 19 1 4.51 19 0 "CZE" 1 0
                0 3 6   1 19 1 4.51 19 0 "CZE" 1 0
                0 3 6   1 19 1 4.51 19 0 "CZE" 1 0
                end

                Comment


                • #9
                  Anna:
                  thanks for providing full details.
                  In my opinion, interaction is not meaningful/feasible/advisable due to amissing value problem, too:
                  Code:
                  . logistic SUCFAI RIGLO FHI ENPP specialbody ParlSemi AGE i.initiator##CSO , vce(cluster Country)
                  note: specialbody != 0 predicts success perfectly
                        specialbody dropped and 1 obs not used
                  
                  note: 2.initiator != 0 predicts success perfectly
                        2.initiator dropped and 2 obs not used
                  
                  note: 4.initiator != 0 predicts success perfectly
                        4.initiator dropped and 1 obs not used
                  
                  note: 3.initiator#0.CSO != 0 predicts failure perfectly
                        3.initiator#0.CSO dropped and 1 obs not used
                  
                  note: 2.initiator#0.CSO identifies no observations in the sample
                  note: 2.initiator#1.CSO omitted because of collinearity
                  note: 3.initiator#1.CSO omitted because of collinearity
                  note: 4.initiator#1.CSO identifies no observations in the sample
                  
                  Logistic regression                             Number of obs     =         81
                                                                  Wald chi2(1)      =          .
                                                                  Prob > chi2       =          .
                  Log pseudolikelihood = -24.317264               Pseudo R2         =     0.1968
                  
                                                   (Std. Err. adjusted for 3 clusters in Country)
                  -------------------------------------------------------------------------------
                                |               Robust
                         SUCFAI | Odds Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
                  --------------+----------------------------------------------------------------
                          RIGLO |   .5243795   .3586928    -0.94   0.345     .1372132     2.00399
                            FHI |   1.516468   1.595678     0.40   0.692     .1928282    11.92603
                           ENPP |   1.044307   .5836235     0.08   0.938       .34924    3.122715
                    specialbody |          1  (omitted)
                       ParlSemi |   .7114512   .6360658    -0.38   0.703     .1233494    4.103489
                            AGE |   1.062549   .0257962     2.50   0.012     1.013173     1.11433
                                |
                      initiator |
                             2  |          1  (empty)
                             3  |   9.505921   4.803241     4.46   0.000     3.530946    25.59159
                             4  |          1  (empty)
                                |
                          1.CSO |   .0274471     .00703   -14.04   0.000     .0166142    .0453435
                                |
                  initiator#CSO |
                           2 0  |          1  (empty)
                           2 1  |          1  (empty)
                           3 0  |          1  (empty)
                           3 1  |          1  (omitted)
                           4 0  |          1  (empty)
                           4 1  |          1  (empty)
                                |
                          _cons |   17.31974   57.88003     0.85   0.393     .0247714    12109.66
                  -------------------------------------------------------------------------------
                  Note: _cons estimates baseline odds.
                  
                  . estat gof
                  
                  Logistic model for SUCFAI, goodness-of-fit test
                  
                         number of observations =        81
                   number of covariate patterns =        37
                               Pearson chi2(29) =        24.27
                                    Prob > chi2 =         0.7153
                  CSO has missing values (I do not know whether you investigated/were asked to investigate them):
                  Code:
                  . codebook CSO
                  
                  ------------------------------------------------------------------------------------------------------------------------
                  CSO                                                                                                          (unlabeled)
                  ------------------------------------------------------------------------------------------------------------------------
                  
                                    type:  numeric (byte)
                  
                                   range:  [0,1]                        units:  1
                           unique values:  2                        missing .:  14/100
                  
                              tabulation:  Freq.  Value
                                               4  0
                                              82  1
                                              14  .
                  In sum, before considering interaction, I think you should pay attention to the missing values issue.
                  Kind regards,
                  Carlo
                  (Stata 19.0)

                  Comment


                  • #10
                    Dear Carlo,
                    thank you for taking the time! Just to clarify: Do you mean the interaction is not meaningful because for one category of the variable initiator I have missing values?
                    I will deal with the missing values for CSO, I have to wait for the input of my co-author.
                    Best wishes
                    Anna

                    Comment


                    • #11
                      Anna:
                      not quite.
                      I would simply pay attention to missing values first (by diagnosing their mechanism and pattern and decide how to dela with them accordingly) and then consider interaction (and/or model specification at large).
                      Kind regards,
                      Carlo
                      (Stata 19.0)

                      Comment

                      Working...
                      X