. do "C:\Users\hstryhn\AppData\Local\Temp\STD2694_000000.tmp"

. * do-file for lecture 4a of VHM 802/812, Winter 2023
. version 17 /* works also with versions 14-16, except for table command */

. set more off

. cd "r:\"
r:\

.
. use nocardia.dta, clear

. tabulate casecont dclox, chi2 row exact lrchi2

+----------------+
| Key            |
+----------------+
|   frequency    |
| row percentage |
+----------------+

           |  Cloxacillin used on
    Case - |         farm
   Control |        no        yes |     Total
-----------+----------------------+----------
        no |        35         19 |        54
           |     64.81      35.19 |    100.00
-----------+----------------------+----------
       yes |        46          8 |        54
           |     85.19      14.81 |    100.00
-----------+----------------------+----------
     Total |        81         27 |       108
           |     75.00      25.00 |    100.00

          Pearson chi2(1) =   5.9753   Pr = 0.015
 Likelihood-ratio chi2(1) =   6.1130   Pr = 0.013
           Fisher's exact =                 0.025
   1-sided Fisher's exact =                 0.013

. cc casecont dclox
                                                         Proportion
                 |   Exposed   Unexposed  |      Total      exposed
-----------------+------------------------+------------------------
           Cases |         8          46  |         54       0.1481
        Controls |        19          35  |         54       0.3519
-----------------+------------------------+------------------------
           Total |        27          81  |        108       0.2500
                 |                        |
                 |      Point estimate    |    [95% conf. interval]
                 +------------------------+------------------------
      Odds ratio |         .3203661       |    .1091298    .8852277 (exact)
 Prev. frac. ex. |         .6796339       |    .1147723    .8908702 (exact)
 Prev. frac. pop |         .2391304       |
                 +------------------------+------------------------
                               chi2(1) =     5.98  Pr>chi2 = 0.0145

. * logistic regression for case-control design
. logit casecont dclox

Iteration 0:   log likelihood = -74.859896
Iteration 1:   log likelihood = -71.810582
Iteration 2:   log likelihood = -71.803418
Iteration 3:   log likelihood = -71.803418

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(1)    = 6.11
                                                        Prob > chi2    = 0.0134
 Log likelihood    = -71.803418                         Pseudo R2     = 0.0408

-------------+----------------------------------------------------------------
     casecont | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
       dclox |   -1.138291    .4774329     -2.38    0.017     -2.074042    -.2025395
       _cons |    .2732933    .2243002      1.22    0.223     -.1663269     .7129136
-------------+----------------------------------------------------------------

. logit casecont dclox, or /* displays ORs */

Iteration 0:   log likelihood = -74.859896
Iteration 1:   log likelihood = -71.810582
Iteration 2:   log likelihood = -71.803418
Iteration 3:   log likelihood = -71.803418

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(1)    = 6.11
                                                        Prob > chi2    = 0.0134
 Log likelihood    = -71.803418                         Pseudo R2     = 0.0408

-------------+----------------------------------------------------------------
     casecont | Odds ratio    Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
       dclox |    .3203661    .1529533     -2.38    0.017      .1256768     .8166542
       _cons |    1.314286    .2947945      1.22    0.223      .8467694     2.039926
-------------+----------------------------------------------------------------


Note: _cons estimates baseline odds.


. logistic casecont dclox  /* same using logistic command */

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(1)    = 6.11
                                                        Prob > chi2    = 0.0134
 Log likelihood    = -71.803418                         Pseudo R2     = 0.0408

-------------+----------------------------------------------------------------
     casecont | Odds ratio    Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
       dclox |    .3203661    .1529533     -2.38    0.017      .1256768     .8166542
       _cons |    1.314286    .2947945      1.22    0.223      .8467694     2.039926
-------------+----------------------------------------------------------------


Note: _cons estimates baseline odds.


. logit dclox casecont /* to demonstrate same log(OR) */

Iteration 0:   log likelihood = -60.732196
Iteration 1:   log likelihood = -57.735076
Iteration 2:   log likelihood = -57.675769
Iteration 3:   log likelihood = -57.675718
Iteration 4:   log likelihood = -57.675718

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(1)    = 6.11
                                                        Prob > chi2    = 0.0134
 Log likelihood    = -57.675718                         Pseudo R2     = 0.0503

-------------+----------------------------------------------------------------
        dclox | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
    casecont |   -1.138291    .4774329     -2.38    0.017     -2.074042    -.2025396
       _cons |   -.6109091    .2849614     -2.14    0.032     -1.169423     -.052395
-------------+----------------------------------------------------------------

.
. * logistic regression for categorical predictor
. tabulate casecont dbarn, chi2 row exact lrchi2

+----------------+
| Key            |
+----------------+
|   frequency    |
| row percentage |
+----------------+

Enumerating sample-space combinations:
stage 3:  enumerations = 1
stage 2:  enumerations = 3
stage 1:  enumerations = 0

    Case - |         dry cow housing
   Control |  freestal   tiestall      other |     Total
-----------+---------------------------------+----------
        no |        13         38          3 |        54
           |     24.07      70.37       5.56 |    100.00
-----------+---------------------------------+----------
       yes |        22         29          3 |        54
           |     40.74      53.70       5.56 |    100.00
-----------+---------------------------------+----------
     Total |        35         67          6 |       108
           |     32.41      62.04       5.56 |    100.00

          Pearson chi2(2) =   3.5232   Pr = 0.172
 Likelihood-ratio chi2(2) =   3.5531   Pr = 0.169
           Fisher's exact =                 0.157

. logit casecont i.dbarn

Iteration 0:   log likelihood = -74.859896
Iteration 1:   log likelihood = -73.083934
Iteration 2:   log likelihood = -73.083342
Iteration 3:   log likelihood = -73.083342

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(2)    = 3.55
                                                        Prob > chi2    = 0.1692
 Log likelihood    = -73.083342                         Pseudo R2     = 0.0237

-------------+----------------------------------------------------------------
     casecont | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
       dbarn |
   tiestall  |   -.7963834    .4279909     -1.86    0.063      -1.63523     .0424632
      other  |   -.5260931    .8882816     -0.59    0.554     -2.267093     1.214907
             |
       _cons |    .5260931    .3498251      1.50    0.133     -.1595516     1.211738
-------------+----------------------------------------------------------------

. logistic casecont i.dbarn

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(2)    = 3.55
                                                        Prob > chi2    = 0.1692
 Log likelihood    = -73.083342                         Pseudo R2     = 0.0237

-------------+----------------------------------------------------------------
     casecont | Odds ratio    Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
       dbarn |
   tiestall  |    .4509569    .1930054     -1.86    0.063      .1949075     1.043378
      other  |    .5909091    .5248937     -0.59    0.554      .1036129      3.36998
             |
       _cons |    1.692308    .5920118      1.50    0.133       .852526     3.359317
-------------+----------------------------------------------------------------


Note: _cons estimates baseline odds.


. testparm i.dbarn /* multiple Wald test for dbarn */


 ( 1)  [casecont]2.dbarn = 0


 ( 2)  [casecont]3.dbarn = 0


           chi2(  2) =    3.46
         Prob > chi2 =    0.1771

.
. * multiple logistic regression
. logit casecont dneo dclox dcpct

Iteration 0:   log likelihood = -74.859896
Iteration 1:   log likelihood = -54.156164
Iteration 2:   log likelihood = -53.993934
Iteration 3:   log likelihood = -53.993656
Iteration 4:   log likelihood = -53.993656

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(3)    = 41.73
                                                        Prob > chi2    = 0.0000
 Log likelihood    = -53.993656                         Pseudo R2     = 0.2787

-------------+----------------------------------------------------------------
     casecont | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
        dneo |    2.212564    .5780423      3.83    0.000      1.079622     3.345506
       dclox |   -1.412516    .5572076     -2.53    0.011     -2.504623    -.3204093
       dcpct |    .0226682    .0071871      3.15    0.002      .0085817     .0367547
       _cons |   -2.984272    .7722467     -3.86    0.000     -4.497848    -1.470697
-------------+----------------------------------------------------------------

. logistic casecont dneo dclox dcpct /* shows ORs */

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(3)    = 41.73
                                                        Prob > chi2    = 0.0000
 Log likelihood    = -53.993656                         Pseudo R2     = 0.2787

-------------+----------------------------------------------------------------
     casecont | Odds ratio    Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
        dneo |    9.139118    5.282797      3.83    0.000      2.943566     28.37493
       dclox |    .2435298    .1356966     -2.53    0.011      .0817064     .7258519
       dcpct |    1.022927    .0073519      3.15    0.002      1.008619     1.037439
       _cons |    .0505763    .0390574     -3.86    0.000      .0111329     .2297654
-------------+----------------------------------------------------------------


Note: _cons estimates baseline odds.


. testparm dclox /* Wald test as chi^2-test, same P as z-test */


 ( 1)  [casecont]dclox = 0


           chi2(  1) =    6.43
         Prob > chi2 =    0.0112

. testparm dneo dclox /* Wald test for dneo+dclox */


 ( 1)  [casecont]dneo = 0


 ( 2)  [casecont]dclox = 0


           chi2(  2) =   21.40
         Prob > chi2 =    0.0000

. * profile likelihood CI for dclox, using logprof add-on command
. logprof dclox

Maximum Profile Log-Likelihood = -53.993656


-------------------------------------------------------------------------------
casecont       |   Coef.               [95% Conf. Interval]
---------------+---------------------------------------------------------------
dclox          |   -1.412516           -2.5473765  -.34321502
-------------------------------------------------------------------------------

.
. * display of iterations of ML estimation
. logit casecont dneo dclox dcpct, trace

-------------
Iteration 0:
Parameter vector:
     casecont:  casecont:  casecont:  casecont:
         dneo      dclox      dcpct      _cons
r1          0          0          0          0

                                                   log likelihood = -74.859896
-------------
Iteration 1:
Parameter vector:
     casecont:  casecont:  casecont:  casecont:
         dneo      dclox      dcpct      _cons
r1   2.235522   -1.60015   .0228446  -2.857956

                                                   log likelihood = -54.156164
-------------
Iteration 2:
Parameter vector:
     casecont:  casecont:  casecont:  casecont:
         dneo      dclox      dcpct      _cons
r1   2.204562  -1.406852   .0225647  -2.974098

                                                   log likelihood = -53.993934
-------------
Iteration 3:
Parameter vector:
     casecont:  casecont:  casecont:  casecont:
         dneo      dclox      dcpct      _cons
r1   2.212543    -1.4125    .022668  -2.984243

                                                   log likelihood = -53.993656
-------------
Iteration 4:
Parameter vector:
     casecont:  casecont:  casecont:  casecont:
         dneo      dclox      dcpct      _cons
r1   2.212564  -1.412516   .0226682  -2.984272

                                                   log likelihood = -53.993656
-------------

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(3)    = 41.73
                                                        Prob > chi2    = 0.0000
 Log likelihood    = -53.993656                         Pseudo R2     = 0.2787

-------------+----------------------------------------------------------------
     casecont | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
        dneo |    2.212564    .5780423      3.83    0.000      1.079622     3.345506
       dclox |   -1.412516    .5572076     -2.53    0.011     -2.504623    -.3204093
       dcpct |    .0226682    .0071871      3.15    0.002      .0085817     .0367547
       _cons |   -2.984272    .7722467     -3.86    0.000     -4.497848    -1.470697
-------------+----------------------------------------------------------------

.
. * likelihood-ratio tests
. logit casecont dneo dclox dcpct

Iteration 0:   log likelihood = -74.859896
Iteration 1:   log likelihood = -54.156164
Iteration 2:   log likelihood = -53.993934
Iteration 3:   log likelihood = -53.993656
Iteration 4:   log likelihood = -53.993656

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(3)    = 41.73
                                                        Prob > chi2    = 0.0000
 Log likelihood    = -53.993656                         Pseudo R2     = 0.2787

-------------+----------------------------------------------------------------
     casecont | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
        dneo |    2.212564    .5780423      3.83    0.000      1.079622     3.345506
       dclox |   -1.412516    .5572076     -2.53    0.011     -2.504623    -.3204093
       dcpct |    .0226682    .0071871      3.15    0.002      .0085817     .0367547
       _cons |   -2.984272    .7722467     -3.86    0.000     -4.497848    -1.470697
-------------+----------------------------------------------------------------

. estimates store full

. logit casecont dneo dcpct

Iteration 0:   log likelihood = -74.859896
Iteration 1:   log likelihood = -57.649097
Iteration 2:   log likelihood = -57.364934
Iteration 3:   log likelihood = -57.364653
Iteration 4:   log likelihood = -57.364653

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(2)    = 34.99
                                                        Prob > chi2    = 0.0000
 Log likelihood    = -57.364653                         Pseudo R2     = 0.2337

-------------+----------------------------------------------------------------
     casecont | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
        dneo |    2.400661    .5634153      4.26    0.000      1.296388     3.504935
       dcpct |    .0190068    .0069935      2.72    0.007      .0052998     .0327138
       _cons |   -3.218885    .7853907     -4.10    0.000     -4.758222    -1.679547
-------------+----------------------------------------------------------------

. lrtest full /* likelihood-ratio test for dclox */

Likelihood-ratio test
Assumption: . nested within full

LR chi2(1)   = 6.74
Prob > chi2   = 0.0094

. logit casecont dcpct

Iteration 0:   log likelihood = -74.859896
Iteration 1:   log likelihood = -69.088754
Iteration 2:   log likelihood = -69.074669
Iteration 3:   log likelihood = -69.074669

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(1)    = 11.57
                                                        Prob > chi2    = 0.0007
 Log likelihood    = -69.074669                         Pseudo R2     = 0.0773

-------------+----------------------------------------------------------------
     casecont | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
       dcpct |    .0189543    .0060179      3.15    0.002      .0071595     .0307492
       _cons |   -1.462424    .5230518     -2.80    0.005     -2.487586    -.4372608
-------------+----------------------------------------------------------------

. lrtest full /* likelihood-ratio test for dneo+dclox */

Likelihood-ratio test
Assumption: . nested within full

LR chi2(2)   = 30.16
Prob > chi2   = 0.0000

. lrtest full, stats /* same with all fit statistics */

Likelihood-ratio test
Assumption: . nested within full

LR chi2(2)   = 30.16
Prob > chi2   = 0.0000

Akaike's information criterion and Bayesian information criterion

-------------+---------------------------------------------------------------
       Model |          N   ll(null)  ll(model)      df        AIC        BIC
-------------+---------------------------------------------------------------
.            |        108   -74.8599  -69.07467       2   142.1493   147.5136
full         |        108   -74.8599  -53.99366       4   115.9873   126.7158
-------------+---------------------------------------------------------------


Note: BIC uses N = number of observations. See [R] BIC note  .


. estimates store red

. logit casecont

Iteration 0:   log likelihood = -74.859896
Iteration 1:   log likelihood = -74.859896

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(0)    = 0.00
                                                        Prob > chi2    = .
 Log likelihood    = -74.859896                         Pseudo R2     = 0.0000

-------------+----------------------------------------------------------------
     casecont | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
       _cons |           0    .1924501      0.00    1.000     -.3771952     .3771952
-------------+----------------------------------------------------------------

. estimates store null

. estimates stats *

Akaike's information criterion and Bayesian information criterion

-------------+---------------------------------------------------------------
       Model |          N   ll(null)  ll(model)      df        AIC        BIC
-------------+---------------------------------------------------------------
full         |        108   -74.8599  -53.99366       4   115.9873   126.7158
red          |        108   -74.8599  -69.07467       2   142.1493   147.5136
null         |        108   -74.8599   -74.8599       1   151.7198   154.4019
-------------+---------------------------------------------------------------


Note: BIC uses N = number of observations. See [R] BIC note  .


. estimates table *

-------------+---------------------------------------
Variable   | full     red     null
-------------+---------------------------------------
        dneo | 2.2125639
       dclox | -1.412516
       dcpct | .02266825     .01895434
       _cons | -2.9842724     -1.4624236     0
-------------+---------------------------------------

.
. use mice.dta, clear

. logit dead dose

Iteration 0:   log likelihood = -75.669723
Iteration 1:   log likelihood = -64.201632
Iteration 2:   log likelihood = -63.944944
Iteration 3:   log likelihood = -63.944713
Iteration 4:   log likelihood = -63.944713

 Logistic regression                                    Number of obs    = 120
                                                        LR chi2(1)    = 23.45
                                                        Prob > chi2    = 0.0000
 Log likelihood    = -63.944713                         Pseudo R2     = 0.1549

-------------+----------------------------------------------------------------
         dead | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
        dose |     14.6369    3.332533      4.39    0.000       8.10526     21.16855
       _cons |   -3.569738    .7053432     -5.06    0.000     -4.952185    -2.187291
-------------+----------------------------------------------------------------

. estimates store red

. * does not work with non-integer dose values: logit dead i.dose
. egen Dose=group(dose), label /* create dose groups (in new variable Dose)  */

. logit dead i.Dose /* dose as categorical predictor */

note: 4.Dose != 0 predicts failure perfectly;
      4.Dose omitted and 10 obs not used.

Iteration 0:   log likelihood = -71.523665
Iteration 1:   log likelihood = -59.113208
Iteration 2:   log likelihood =  -58.82041
Iteration 3:   log likelihood = -58.817856
Iteration 4:   log likelihood = -58.817856

 Logistic regression                                    Number of obs    = 110
                                                        LR chi2(10)    = 25.41
                                                        Prob > chi2    = 0.0046
 Log likelihood    = -58.817856                         Pseudo R2     = 0.1776

-------------+----------------------------------------------------------------
         dead | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
        Dose |
         .1  |      .81093    1.317616      0.62    0.538     -1.771549     3.393409
      .1259  |   -9.56e-17    1.490712     -0.00    1.000     -2.921742     2.921742
      .1413  |           0   (empty)
        .15  |   -9.56e-17    1.490712     -0.00    1.000     -2.921742     2.921742
      .1588  |      .81093    1.317616      0.62    0.538     -1.771549     3.393409
      .1778  |    1.791759    1.236033      1.45    0.147     -.6308209     4.214339
      .1995  |     2.60269    1.236033      2.11    0.035      .1801093      5.02527
      .2239  |    1.791759    1.236033      1.45    0.147     -.6308209     4.214339
      .2512  |    2.197224    1.229273      1.79    0.074     -.2121055     4.606554
      .2818  |    2.197224    1.229273      1.79    0.074     -.2121055     4.606554
      .3162  |    3.583519    1.317616      2.72    0.007       1.00104     6.165998
             |
       _cons |   -2.197224    1.054092     -2.08    0.037     -4.263208    -.1312411
-------------+----------------------------------------------------------------

. logit dead i.Dose, asis /* avoids exclusion of dose=0.1413 */

Iteration 0:   log likelihood = -75.669723
Iteration 1:   log likelihood = -60.073875
Iteration 2:   log likelihood = -59.076968
Iteration 3:   log likelihood = -58.874743
Iteration 4:   log likelihood = -58.831027
Iteration 5:   log likelihood = -58.820395
Iteration 6:   log likelihood =  -58.81828
Iteration 7:   log likelihood = -58.817905
Iteration 8:   log likelihood = -58.817866
Iteration 9:   log likelihood = -58.817858
Iteration 10:  log likelihood = -58.817856

 Logistic regression                                    Number of obs    = 120
                                                        LR chi2(11)    = 33.70
                                                        Prob > chi2    = 0.0004
 Log likelihood    = -58.817856                         Pseudo R2     = 0.2227

-------------+----------------------------------------------------------------
         dead | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
        Dose |
         .1  |    .8110233     1.31765      0.62    0.538     -1.771523      3.39357
      .1259  |   -7.83e-16    1.490771     -0.00    1.000     -2.921858     2.921858
      .1413  |   -14.73911    1505.568     -0.01    0.992     -2965.599      2936.12
        .15  |    2.90e-16    1.490771      0.00    1.000     -2.921858     2.921858
      .1588  |    .8110233     1.31765      0.62    0.538     -1.771523      3.39357
      .1778  |    1.791833     1.23607      1.45    0.147     -.6308193     4.214485
      .1995  |    2.602659    1.236064      2.11    0.035      .1800167       5.0253
      .2239  |    1.791833     1.23607      1.45    0.147     -.6308193     4.214485
      .2512  |    2.197249    1.229309      1.79    0.074     -.2121518     4.606649
      .2818  |    2.197249    1.229309      1.79    0.074     -.2121518     4.606649
      .3162  |    3.583471    1.317628      2.72    0.007      1.000967     6.165976
             |
       _cons |   -2.197324    1.054134     -2.08    0.037      -4.26339    -.1312584
-------------+----------------------------------------------------------------

. logit dead i.Dose, asis trace /* showing convergence process */

-------------
Iteration 0:
Parameter vector:
         dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:
           1b.         2.         3.         4.         5.         6.         7.         8.         9.        10.        11.
         Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose
r1          0          0          0          0          0          0          0          0          0          0          0

         dead:      dead:
           12.
         Dose      _cons
r1          0  -.7308875

                                                   log likelihood = -75.669723
-------------
Iteration 1:
Parameter vector:
         dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:
           1b.         2.         3.         4.         5.         6.         7.         8.         9.        10.        11.
         Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose
r1          0   .5128205   1.14e-14  -.5128205   1.14e-14   .5128205   1.538462   2.564103   1.538462   2.051282   2.051282

         dead:      dead:
           12.
         Dose      _cons
r1   3.589744  -1.884734

                                                   log likelihood = -60.073875
-------------
Iteration 2:
Parameter vector:
         dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:
           1b.         2.         3.         4.         5.         6.         7.         8.         9.        10.        11.
         Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose
r1          0   .8756869  -2.01e-15  -1.630307  -2.01e-15   .8756869   1.840062   2.554934   1.840062   2.203774   2.203774

         dead:      dead:
           12.
         Dose      _cons
r1   3.484351   -2.26729

                                                   log likelihood = -59.076968
-------------
Iteration 3:
Parameter vector:
         dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:
           1b.         2.         3.         4.         5.         6.         7.         8.         9.        10.        11.
         Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose
r1          0   .7838782   2.26e-15  -3.132326   2.26e-15   .7838782   1.770934   2.616282   1.770934   2.192047   2.192047

         dead:      dead:
           12.
         Dose      _cons
r1   3.607197   -2.16817

                                                   log likelihood = -58.874743
-------------
Iteration 4:
Parameter vector:
         dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:
           1b.         2.         3.         4.         5.         6.         7.         8.         9.        10.        11.
         Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose
r1          0   .8339775  -4.60e-15  -4.962829  -4.60e-15   .8339775   1.809369   2.589805   1.809369   2.201125   2.201125

         dead:      dead:
           12.
         Dose      _cons
r1   3.560565  -2.222022

                                                   log likelihood = -58.831027
-------------
Iteration 5:
Parameter vector:
         dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:
           1b.         2.         3.         4.         5.         6.         7.         8.         9.        10.        11.
         Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose
r1          0   .8077708  -4.61e-17  -6.116858  -1.71e-16   .8077708   1.789285   2.603871   1.789285   2.196459   2.196459

         dead:      dead:
           12.
         Dose      _cons
r1   3.585359  -2.193845

                                                   log likelihood = -58.820395
-------------
Iteration 6:
Parameter vector:
         dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:
           1b.         2.         3.         4.         5.         6.         7.         8.         9.        10.        11.
         Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose
r1          0   .8168411  -1.36e-15  -8.982863  -1.49e-15   .8168411   1.796387   2.600456   1.796387   2.198647   2.198647

         dead:      dead:
           12.
         Dose      _cons
r1   3.580031  -2.203547

                                                   log likelihood =  -58.81828
-------------
Iteration 7:
Parameter vector:
         dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:
           1b.         2.         3.         4.         5.         6.         7.         8.         9.        10.        11.
         Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose
r1          0   .8101734  -3.32e-16  -10.11501  -4.42e-16   .8101734   1.791163   2.602943   1.791163   2.197029   2.197029

         dead:      dead:
           12.
         Dose      _cons
r1   3.583905  -2.196416

                                                   log likelihood = -58.817905
-------------
Iteration 8:
Parameter vector:
         dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:
           1b.         2.         3.         4.         5.         6.         7.         8.         9.        10.        11.
         Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose
r1          0    .811592  -1.16e-15   -11.9885  -1.27e-15    .811592   1.792281   2.602468   1.792281   2.197395   2.197395

         dead:      dead:
           12.
         Dose      _cons
r1    3.58318  -2.197931

                                                   log likelihood = -58.817866
-------------
Iteration 9:
Parameter vector:
         dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:
           1b.         2.         3.         4.         5.         6.         7.         8.         9.        10.        11.
         Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose
r1          0   .8106818   7.71e-16  -13.36448   6.59e-16   .8106818   1.791564   2.602773   1.791564    2.19716    2.19716

         dead:      dead:
           12.
         Dose      _cons
r1   3.583645  -2.196959

                                                   log likelihood = -58.817858
-------------
Iteration 10:
Parameter vector:
         dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:      dead:
           1b.         2.         3.         4.         5.         6.         7.         8.         9.        10.        11.
         Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose       Dose
r1          0   .8110233  -7.83e-16  -14.73911   2.90e-16   .8110233   1.791833   2.602659   1.791833   2.197249   2.197249

         dead:      dead:
           12.
         Dose      _cons
r1   3.583471  -2.197324

                                                   log likelihood = -58.817856
-------------

 Logistic regression                                    Number of obs    = 120
                                                        LR chi2(11)    = 33.70
                                                        Prob > chi2    = 0.0004
 Log likelihood    = -58.817856                         Pseudo R2     = 0.2227

-------------+----------------------------------------------------------------
         dead | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
        Dose |
         .1  |    .8110233     1.31765      0.62    0.538     -1.771523      3.39357
      .1259  |   -7.83e-16    1.490771     -0.00    1.000     -2.921858     2.921858
      .1413  |   -14.73911    1505.568     -0.01    0.992     -2965.599      2936.12
        .15  |    2.90e-16    1.490771      0.00    1.000     -2.921858     2.921858
      .1588  |    .8110233     1.31765      0.62    0.538     -1.771523      3.39357
      .1778  |    1.791833     1.23607      1.45    0.147     -.6308193     4.214485
      .1995  |    2.602659    1.236064      2.11    0.035      .1800167       5.0253
      .2239  |    1.791833     1.23607      1.45    0.147     -.6308193     4.214485
      .2512  |    2.197249    1.229309      1.79    0.074     -.2121518     4.606649
      .2818  |    2.197249    1.229309      1.79    0.074     -.2121518     4.606649
      .3162  |    3.583471    1.317628      2.72    0.007      1.000967     6.165976
             |
       _cons |   -2.197324    1.054134     -2.08    0.037      -4.26339    -.1312584
-------------+----------------------------------------------------------------

. testparm i.Dose /* note: multiple Wald test for dose fails here, LR-test = 33.70 */


 ( 1)  [dead]2.Dose = 0


 ( 2)  [dead]3.Dose = 0


 ( 3)  [dead]4.Dose = 0


 ( 4)  [dead]5.Dose = 0


 ( 5)  [dead]6.Dose = 0


 ( 6)  [dead]7.Dose = 0


 ( 7)  [dead]8.Dose = 0


 ( 8)  [dead]9.Dose = 0


 ( 9)  [dead]10.Dose = 0


 (10)  [dead]11.Dose = 0


 (11)  [dead]12.Dose = 0


           chi2( 11) =   19.22
         Prob > chi2 =    0.0573

. lrtest red, stats /* likelihood-ratio (goodness-of-fit) test ok */

Likelihood-ratio test
Assumption: red nested within .

LR chi2(10)   = 10.25
Prob > chi2   = 0.4185

Akaike's information criterion and Bayesian information criterion

-------------+---------------------------------------------------------------
       Model |          N   ll(null)  ll(model)      df        AIC        BIC
-------------+---------------------------------------------------------------
red          |        120  -75.66972  -63.94471       2   131.8894   137.4644
.            |        120  -75.66972  -58.81786      12   141.6357   175.0856
-------------+---------------------------------------------------------------


Note: BIC uses N = number of observations. See [R] BIC note  .


.
. * prediction after logistic regression for Nocardia data
. use nocardia.dta, clear

. * effects on probability scale
. logit casecont i.dneo i.dclox dcpct

Iteration 0:   log likelihood = -74.859896
Iteration 1:   log likelihood = -54.156164
Iteration 2:   log likelihood = -53.993934
Iteration 3:   log likelihood = -53.993656
Iteration 4:   log likelihood = -53.993656

 Logistic regression                                    Number of obs    = 108
                                                        LR chi2(3)    = 41.73
                                                        Prob > chi2    = 0.0000
 Log likelihood    = -53.993656                         Pseudo R2     = 0.2787

-------------+----------------------------------------------------------------
     casecont | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
        dneo |
        yes  |    2.212564    .5780423      3.83    0.000      1.079622     3.345506
             |
       dclox |
        yes  |   -1.412516    .5572076     -2.53    0.011     -2.504623    -.3204093
       dcpct |    .0226682    .0071871      3.15    0.002      .0085817     .0367547
       _cons |   -2.984272    .7722467     -3.86    0.000     -4.497848    -1.470697
-------------+----------------------------------------------------------------

. predict phat
(option pr assumed; Pr(casecont))

. predict logitphat, xb

. * plots of predicted values - for demonstration only (not valid in case-control study)
. twoway (connected logitphat dcpct if dneo==1 & dclox==0, sort) (connected logitphat dcpct if dneo==0 & dclox==0, sort)

. twoway (connected phat dcpct if dneo==1 & dclox==0, sort) (connected phat dcpct if dneo==0 & dclox==0, sort)

. * manually created prediction values and plots
. set obs 119


Number of observations (_N) was 108,
now 119.


. replace dneo=0 in 109/119
(11 real changes made)

. replace dclox=0 in 109/119
(11 real changes made)

. replace dcpct=0+(_n-109)*10 in 109/119
(11 real changes made)

. capture drop phat logitphat

. predict phat
(option pr assumed; Pr(casecont))

. predict logitphat, xb

. twoway (connected logitphat dcpct in 109/119, sort)

. twoway (connected phat dcpct in 109/119, sort)

.
. * estimation and plots by margins and marginsplot commands
. * logit scale
. margins, at(dcpct=(0(10)100) dneo=1 dclox=0) at(dcpct=(0(10)100) dneo=0 dclox=0) predict(xb) plot

 Adjusted predictions                                      Number of obs    = 108
 Model VCE: OIM


Expression:  Linear prediction (log odds), predict(xb)


1._at:   dneo   = 1
  dclox   = 0
  dcpct   = 0
2._at:   dneo   = 1
  dclox   = 0
  dcpct   = 10
3._at:   dneo   = 1
  dclox   = 0
  dcpct   = 20
4._at:   dneo   = 1
  dclox   = 0
  dcpct   = 30
5._at:   dneo   = 1
  dclox   = 0
  dcpct   = 40
6._at:   dneo   = 1
  dclox   = 0
  dcpct   = 50
7._at:   dneo   = 1
  dclox   = 0
  dcpct   = 60
8._at:   dneo   = 1
  dclox   = 0
  dcpct   = 70
9._at:   dneo   = 1
  dclox   = 0
  dcpct   = 80
10._at:   dneo   = 1
  dclox   = 0
  dcpct   = 90
11._at:   dneo   = 1
  dclox   = 0
  dcpct   = 100
12._at:   dneo   = 0
  dclox   = 0
  dcpct   = 0
13._at:   dneo   = 0
  dclox   = 0
  dcpct   = 10
14._at:   dneo   = 0
  dclox   = 0
  dcpct   = 20
15._at:   dneo   = 0
  dclox   = 0
  dcpct   = 30
16._at:   dneo   = 0
  dclox   = 0
  dcpct   = 40
17._at:   dneo   = 0
  dclox   = 0
  dcpct   = 50
18._at:   dneo   = 0
  dclox   = 0
  dcpct   = 60
19._at:   dneo   = 0
  dclox   = 0
  dcpct   = 70
20._at:   dneo   = 0
  dclox   = 0
  dcpct   = 80
21._at:   dneo   = 0
  dclox   = 0
  dcpct   = 90
22._at:   dneo   = 0
  dclox   = 0
  dcpct   = 100

-------------+----------------------------------------------------------------
             |            Delta-method
             |     Margin    std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
         _at |
          1  |   -.7717085    .5987154     -1.29    0.197     -1.945169     .4017521
          2  |    -.545026    .5378343     -1.01    0.311     -1.599162     .5091099
          3  |   -.3183436    .4800024     -0.66    0.507     -1.259131     .6224439
          4  |   -.0916611     .426462     -0.21    0.830     -.9275113      .744189
          5  |    .1350213     .379036      0.36    0.722     -.6078756     .8779183
          6  |    .3617038    .3402906      1.06    0.288     -.3052536     1.028661
          7  |    .5883862    .3134615      1.88    0.061     -.0259869     1.202759
          8  |    .8150687    .3017439      2.70    0.007      .2236615     1.406476
          9  |    1.041751     .306874      3.39    0.001      .4402891     1.643213
         10  |    1.268434    .3280623      3.87    0.000      .6254433     1.911424
         11  |    1.495116    .3625038      4.12    0.000      .7846216     2.205611
         12  |   -2.984272    .7722467     -3.86    0.000     -4.497848    -1.470697
         13  |    -2.75759    .7219825     -3.82    0.000      -4.17265     -1.34253
         14  |   -2.530907    .6756357     -3.75    0.000     -3.855129    -1.206686
         15  |   -2.304225    .6340656     -3.63    0.000     -3.546971    -1.061479
         16  |   -2.077543    .5982691     -3.47    0.001     -3.250128    -.9049568
         17  |    -1.85086     .569336     -3.25    0.001     -2.966738    -.7349821
         18  |   -1.624178    .5483539     -2.96    0.003     -2.698932    -.5494237
         19  |   -1.397495    .5362569     -2.61    0.009     -2.448539    -.3464509
         20  |   -1.170813    .5336496     -2.19    0.028     -2.216747    -.1248787
         21  |   -.9441303    .5406693     -1.75    0.081     -2.003823     .1155621
         22  |   -.7174478    .5569521     -1.29    0.198     -1.809054     .3741583
-------------+----------------------------------------------------------------


Variables that uniquely identify margins: dcpct _atopt


Multiple at() options specified:


_atoption=1: dcpct=(0(10)100) dneo=1 dclox=0


_atoption=2: dcpct=(0(10)100) dneo=0 dclox=0


. * probability scale, the default
. margins, at(dcpct=(0(10)100) dneo=1 dclox=0) at(dcpct=(0(10)100) dneo=0 dclox=0)

 Adjusted predictions                                      Number of obs    = 108
 Model VCE: OIM


Expression:  Pr(casecont), predict()


1._at:   dneo   = 1
  dclox   = 0
  dcpct   = 0
2._at:   dneo   = 1
  dclox   = 0
  dcpct   = 10
3._at:   dneo   = 1
  dclox   = 0
  dcpct   = 20
4._at:   dneo   = 1
  dclox   = 0
  dcpct   = 30
5._at:   dneo   = 1
  dclox   = 0
  dcpct   = 40
6._at:   dneo   = 1
  dclox   = 0
  dcpct   = 50
7._at:   dneo   = 1
  dclox   = 0
  dcpct   = 60
8._at:   dneo   = 1
  dclox   = 0
  dcpct   = 70
9._at:   dneo   = 1
  dclox   = 0
  dcpct   = 80
10._at:   dneo   = 1
  dclox   = 0
  dcpct   = 90
11._at:   dneo   = 1
  dclox   = 0
  dcpct   = 100
12._at:   dneo   = 0
  dclox   = 0
  dcpct   = 0
13._at:   dneo   = 0
  dclox   = 0
  dcpct   = 10
14._at:   dneo   = 0
  dclox   = 0
  dcpct   = 20
15._at:   dneo   = 0
  dclox   = 0
  dcpct   = 30
16._at:   dneo   = 0
  dclox   = 0
  dcpct   = 40
17._at:   dneo   = 0
  dclox   = 0
  dcpct   = 50
18._at:   dneo   = 0
  dclox   = 0
  dcpct   = 60
19._at:   dneo   = 0
  dclox   = 0
  dcpct   = 70
20._at:   dneo   = 0
  dclox   = 0
  dcpct   = 80
21._at:   dneo   = 0
  dclox   = 0
  dcpct   = 90
22._at:   dneo   = 0
  dclox   = 0
  dcpct   = 100

-------------+----------------------------------------------------------------
             |            Delta-method
             |     Margin    std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
         _at |
          1  |    .3161096    .1294329      2.44    0.015      .0624258     .5697934
          2  |    .3670192    .1249476      2.94    0.003      .1221264     .6119119
          3  |    .4210795    .1170109      3.60    0.000      .1917423     .6504167
          4  |    .4771007    .1063919      4.48    0.000      .2685765      .685625
          5  |    .5337041    .0943284      5.66    0.000      .3488238     .7185845
          6  |    .5894528    .0823497      7.16    0.000      .4280503     .7508553
          7  |    .6429948    .0719559      8.94    0.000      .5019639     .7840257
          8  |    .6931886    .0641743     10.80    0.000      .5674091      .818968
          9  |    .7391878     .059162     12.49    0.000      .6232324     .8551431
         10  |    .7804745    .0562082     13.89    0.000      .6703084     .8906406
         11  |    .8168449    .0542339     15.06    0.000      .7105483     .9231415
         12  |    .0481415    .0353873      1.36    0.174     -.0212164     .1174994
         13  |    .0596594    .0405034      1.47    0.141     -.0197257     .1390445
         14  |    .0737197    .0461358      1.60    0.110     -.0167049     .1641442
         15  |    .0907736    .0523318      1.73    0.083     -.0117949     .1933422
         16  |    .1112988    .0591756      1.88    0.060     -.0046833     .2272809
         17  |    .1357719    .0668047      2.03    0.042      .0048371     .2667067
         18  |    .1646295    .0754133      2.18    0.029      .0168222     .3124368
         19  |    .1982139    .0852247      2.33    0.020      .0311765     .3652512
         20  |    .2367081    .0964184      2.46    0.014      .0477315     .4256847
         21  |    .2800668    .1090148      2.57    0.010      .0664017     .4937319
         22  |    .3279552    .1227526      2.67    0.008      .0873646     .5685459
-------------+----------------------------------------------------------------

. marginsplot, noci /* CIs not quite correct anyway */


Variables that uniquely identify margins: dcpct _atopt


Multiple at() options specified:


_atoption=1: dcpct=(0(10)100) dneo=1 dclox=0


_atoption=2: dcpct=(0(10)100) dneo=0 dclox=0


. margins, over(dcpct) at(dneo=1 dclox=0) at(dneo=0 dclox=0)

 Predictive margins                                        Number of obs    = 108
 Model VCE: OIM


Expression:  Pr(casecont), predict()


Over:  dcpct


1._at: 0.dcpct
      dneo   = 1
      dclox   = 0
       1.dcpct
      dneo   = 1
      dclox   = 0
       3.dcpct
      dneo   = 1
      dclox   = 0
       5.dcpct
      dneo   = 1
      dclox   = 0
       7.dcpct
      dneo   = 1
      dclox   = 0
       10.dcpct
      dneo   = 1
      dclox   = 0
       14.dcpct
      dneo   = 1
      dclox   = 0
       20.dcpct
      dneo   = 1
      dclox   = 0
       25.dcpct
      dneo   = 1
      dclox   = 0
       30.dcpct
      dneo   = 1
      dclox   = 0
       40.dcpct
      dneo   = 1
      dclox   = 0
       50.dcpct
      dneo   = 1
      dclox   = 0
       75.dcpct
      dneo   = 1
      dclox   = 0
       80.dcpct
      dneo   = 1
      dclox   = 0
       83.dcpct
      dneo   = 1
      dclox   = 0
       90.dcpct
      dneo   = 1
      dclox   = 0
       95.dcpct
      dneo   = 1
      dclox   = 0
       99.dcpct
      dneo   = 1
      dclox   = 0
       100.dcpct
      dneo   = 1
      dclox   = 0
2._at: 0.dcpct
      dneo   = 0
      dclox   = 0
       1.dcpct
      dneo   = 0
      dclox   = 0
       3.dcpct
      dneo   = 0
      dclox   = 0
       5.dcpct
      dneo   = 0
      dclox   = 0
       7.dcpct
      dneo   = 0
      dclox   = 0
       10.dcpct
      dneo   = 0
      dclox   = 0
       14.dcpct
      dneo   = 0
      dclox   = 0
       20.dcpct
      dneo   = 0
      dclox   = 0
       25.dcpct
      dneo   = 0
      dclox   = 0
       30.dcpct
      dneo   = 0
      dclox   = 0
       40.dcpct
      dneo   = 0
      dclox   = 0
       50.dcpct
      dneo   = 0
      dclox   = 0
       75.dcpct
      dneo   = 0
      dclox   = 0
       80.dcpct
      dneo   = 0
      dclox   = 0
       83.dcpct
      dneo   = 0
      dclox   = 0
       90.dcpct
      dneo   = 0
      dclox   = 0
       95.dcpct
      dneo   = 0
      dclox   = 0
       99.dcpct
      dneo   = 0
      dclox   = 0
       100.dcpct
      dneo   = 0
      dclox   = 0

-------------+----------------------------------------------------------------
             |            Delta-method
             |     Margin    std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
   _at#dcpct |
      1   0  |    .3161096    .1294329      2.44    0.015      .0624258     .5697934
      1   1  |    .3210305    .1291508      2.49    0.013      .0678996     .5741613
      1   3  |    .3309916    .1284744      2.58    0.010      .0791864     .5827968
      1   5  |    .3411065    .1276492      2.67    0.008      .0909186     .5912944
      1   7  |    .3513681    .1266768      2.77    0.006      .1030861     .5996502
      1  10  |    .3670192    .1249476      2.94    0.003      .1221264     .6119119
      1  14  |    .3883263    .1221557      3.18    0.001      .1489056      .627747
      1  20  |    .4210795    .1170109      3.60    0.000      .1917423     .6504167
      1  25  |    .4489281    .1119689      4.01    0.000      .2294731     .6683832
      1  30  |    .4771007    .1063919      4.48    0.000      .2685765      .685625
      1  40  |    .5337041    .0943284      5.66    0.000      .3488238     .7185845
      1  50  |    .5894528    .0823497      7.16    0.000      .4280503     .7508553
      1  75  |    .7167526    .0613502     11.68    0.000      .5965083     .8369968
      1  80  |    .7391878     .059162     12.49    0.000      .6232324     .8551431
      1  83  |    .7520836    .0581075     12.94    0.000       .638195     .8659722
      1  90  |    .7804745    .0562082     13.89    0.000      .6703084     .8906406
      1  95  |    .7992759    .0551635     14.49    0.000      .6911574     .9073944
      1  99  |    .8134292    .0544159     14.95    0.000      .7067759     .9200824
      1 100  |    .8168449    .0542339     15.06    0.000      .7105483     .9231415
      2   0  |    .0481415    .0353873      1.36    0.174     -.0212164     .1174994
      2   1  |    .0491909    .0358766      1.37    0.170     -.0211258     .1195077
      2   3  |    .0513552    .0368698      1.39    0.164     -.0209082     .1236186
      2   5  |    .0536094    .0378828      1.42    0.157     -.0206395     .1278583
      2   7  |    .0559567    .0389158      1.44    0.150     -.0203169     .1322302
      2  10  |    .0596594    .0405034      1.47    0.141     -.0197257     .1390445
      2  14  |     .064954    .0426923      1.52    0.128     -.0187215     .1486294
      2  20  |    .0737197    .0461358      1.60    0.110     -.0167049     .1641442
      2  25  |     .081843    .0491592      1.66    0.096     -.0145073     .1781932
      2  30  |    .0907736    .0523318      1.73    0.083     -.0117949     .1933422
      2  40  |    .1112988    .0591756      1.88    0.060     -.0046833     .2272809
      2  50  |    .1357719    .0668047      2.03    0.042      .0048371     .2667067
      2  75  |     .216844    .0906423      2.39    0.017      .0391884     .3944995
      2  80  |    .2367081    .0964184      2.46    0.014      .0477315     .4256847
      2  83  |    .2492141    .1000555      2.49    0.013      .0531089     .4453194
      2  90  |    .2800668    .1090148      2.57    0.010      .0664017     .4937319
      2  95  |    .3034783     .115771      2.62    0.009      .0765712     .5303853
      2  99  |    .3229788    .1213422      2.66    0.008      .0851524     .5608051
      2 100  |    .3279552    .1227526      2.67    0.008      .0873646     .5685459
-------------+----------------------------------------------------------------

. marginsplot, noci /* CIs not quite correct anyway */


Variables that uniquely identify margins: dcpct _atopt


Multiple at() options specified:


_atoption=1: dneo=1 dclox=0


_atoption=2: dneo=0 dclox=0


. * figure in lecture
. margins, over(dcpct) at(dneo=0 dclox=0) at(dneo=1 dclox=0) at(dneo=0 dclox=1) at(dneo=1 dclox=1)

 Predictive margins                                        Number of obs    = 108
 Model VCE: OIM


Expression:  Pr(casecont), predict()


Over:  dcpct


1._at: 0.dcpct
      dneo   = 0
      dclox   = 0
       1.dcpct
      dneo   = 0
      dclox   = 0
       3.dcpct
      dneo   = 0
      dclox   = 0
       5.dcpct
      dneo   = 0
      dclox   = 0
       7.dcpct
      dneo   = 0
      dclox   = 0
       10.dcpct
      dneo   = 0
      dclox   = 0
       14.dcpct
      dneo   = 0
      dclox   = 0
       20.dcpct
      dneo   = 0
      dclox   = 0
       25.dcpct
      dneo   = 0
      dclox   = 0
       30.dcpct
      dneo   = 0
      dclox   = 0
       40.dcpct
      dneo   = 0
      dclox   = 0
       50.dcpct
      dneo   = 0
      dclox   = 0
       75.dcpct
      dneo   = 0
      dclox   = 0
       80.dcpct
      dneo   = 0
      dclox   = 0
       83.dcpct
      dneo   = 0
      dclox   = 0
       90.dcpct
      dneo   = 0
      dclox   = 0
       95.dcpct
      dneo   = 0
      dclox   = 0
       99.dcpct
      dneo   = 0
      dclox   = 0
       100.dcpct
      dneo   = 0
      dclox   = 0
2._at: 0.dcpct
      dneo   = 1
      dclox   = 0
       1.dcpct
      dneo   = 1
      dclox   = 0
       3.dcpct
      dneo   = 1
      dclox   = 0
       5.dcpct
      dneo   = 1
      dclox   = 0
       7.dcpct
      dneo   = 1
      dclox   = 0
       10.dcpct
      dneo   = 1
      dclox   = 0
       14.dcpct
      dneo   = 1
      dclox   = 0
       20.dcpct
      dneo   = 1
      dclox   = 0
       25.dcpct
      dneo   = 1
      dclox   = 0
       30.dcpct
      dneo   = 1
      dclox   = 0
       40.dcpct
      dneo   = 1
      dclox   = 0
       50.dcpct
      dneo   = 1
      dclox   = 0
       75.dcpct
      dneo   = 1
      dclox   = 0
       80.dcpct
      dneo   = 1
      dclox   = 0
       83.dcpct
      dneo   = 1
      dclox   = 0
       90.dcpct
      dneo   = 1
      dclox   = 0
       95.dcpct
      dneo   = 1
      dclox   = 0
       99.dcpct
      dneo   = 1
      dclox   = 0
       100.dcpct
      dneo   = 1
      dclox   = 0
3._at: 0.dcpct
      dneo   = 0
      dclox   = 1
       1.dcpct
      dneo   = 0
      dclox   = 1
       3.dcpct
      dneo   = 0
      dclox   = 1
       5.dcpct
      dneo   = 0
      dclox   = 1
       7.dcpct
      dneo   = 0
      dclox   = 1
       10.dcpct
      dneo   = 0
      dclox   = 1
       14.dcpct
      dneo   = 0
      dclox   = 1
       20.dcpct
      dneo   = 0
      dclox   = 1
       25.dcpct
      dneo   = 0
      dclox   = 1
       30.dcpct
      dneo   = 0
      dclox   = 1
       40.dcpct
      dneo   = 0
      dclox   = 1
       50.dcpct
      dneo   = 0
      dclox   = 1
       75.dcpct
      dneo   = 0
      dclox   = 1
       80.dcpct
      dneo   = 0
      dclox   = 1
       83.dcpct
      dneo   = 0
      dclox   = 1
       90.dcpct
      dneo   = 0
      dclox   = 1
       95.dcpct
      dneo   = 0
      dclox   = 1
       99.dcpct
      dneo   = 0
      dclox   = 1
       100.dcpct
      dneo   = 0
      dclox   = 1
4._at: 0.dcpct
      dneo   = 1
      dclox   = 1
       1.dcpct
      dneo   = 1
      dclox   = 1
       3.dcpct
      dneo   = 1
      dclox   = 1
       5.dcpct
      dneo   = 1
      dclox   = 1
       7.dcpct
      dneo   = 1
      dclox   = 1
       10.dcpct
      dneo   = 1
      dclox   = 1
       14.dcpct
      dneo   = 1
      dclox   = 1
       20.dcpct
      dneo   = 1
      dclox   = 1
       25.dcpct
      dneo   = 1
      dclox   = 1
       30.dcpct
      dneo   = 1
      dclox   = 1
       40.dcpct
      dneo   = 1
      dclox   = 1
       50.dcpct
      dneo   = 1
      dclox   = 1
       75.dcpct
      dneo   = 1
      dclox   = 1
       80.dcpct
      dneo   = 1
      dclox   = 1
       83.dcpct
      dneo   = 1
      dclox   = 1
       90.dcpct
      dneo   = 1
      dclox   = 1
       95.dcpct
      dneo   = 1
      dclox   = 1
       99.dcpct
      dneo   = 1
      dclox   = 1
       100.dcpct
      dneo   = 1
      dclox   = 1

-------------+----------------------------------------------------------------
             |            Delta-method
             |     Margin    std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
   _at#dcpct |
      1   0  |    .0481415    .0353873      1.36    0.174     -.0212164     .1174994
      1   1  |    .0491909    .0358766      1.37    0.170     -.0211258     .1195077
      1   3  |    .0513552    .0368698      1.39    0.164     -.0209082     .1236186
      1   5  |    .0536094    .0378828      1.42    0.157     -.0206395     .1278583
      1   7  |    .0559567    .0389158      1.44    0.150     -.0203169     .1322302
      1  10  |    .0596594    .0405034      1.47    0.141     -.0197257     .1390445
      1  14  |     .064954    .0426923      1.52    0.128     -.0187215     .1486294
      1  20  |    .0737197    .0461358      1.60    0.110     -.0167049     .1641442
      1  25  |     .081843    .0491592      1.66    0.096     -.0145073     .1781932
      1  30  |    .0907736    .0523318      1.73    0.083     -.0117949     .1933422
      1  40  |    .1112988    .0591756      1.88    0.060     -.0046833     .2272809
      1  50  |    .1357719    .0668047      2.03    0.042      .0048371     .2667067
      1  75  |     .216844    .0906423      2.39    0.017      .0391884     .3944995
      1  80  |    .2367081    .0964184      2.46    0.014      .0477315     .4256847
      1  83  |    .2492141    .1000555      2.49    0.013      .0531089     .4453194
      1  90  |    .2800668    .1090148      2.57    0.010      .0664017     .4937319
      1  95  |    .3034783     .115771      2.62    0.009      .0765712     .5303853
      1  99  |    .3229788    .1213422      2.66    0.008      .0851524     .5608051
      1 100  |    .3279552    .1227526      2.67    0.008      .0873646     .5685459
      2   0  |    .3161096    .1294329      2.44    0.015      .0624258     .5697934
      2   1  |    .3210305    .1291508      2.49    0.013      .0678996     .5741613
      2   3  |    .3309916    .1284744      2.58    0.010      .0791864     .5827968
      2   5  |    .3411065    .1276492      2.67    0.008      .0909186     .5912944
      2   7  |    .3513681    .1266768      2.77    0.006      .1030861     .5996502
      2  10  |    .3670192    .1249476      2.94    0.003      .1221264     .6119119
      2  14  |    .3883263    .1221557      3.18    0.001      .1489056      .627747
      2  20  |    .4210795    .1170109      3.60    0.000      .1917423     .6504167
      2  25  |    .4489281    .1119689      4.01    0.000      .2294731     .6683832
      2  30  |    .4771007    .1063919      4.48    0.000      .2685765      .685625
      2  40  |    .5337041    .0943284      5.66    0.000      .3488238     .7185845
      2  50  |    .5894528    .0823497      7.16    0.000      .4280503     .7508553
      2  75  |    .7167526    .0613502     11.68    0.000      .5965083     .8369968
      2  80  |    .7391878     .059162     12.49    0.000      .6232324     .8551431
      2  83  |    .7520836    .0581075     12.94    0.000       .638195     .8659722
      2  90  |    .7804745    .0562082     13.89    0.000      .6703084     .8906406
      2  95  |    .7992759    .0551635     14.49    0.000      .6911574     .9073944
      2  99  |    .8134292    .0544159     14.95    0.000      .7067759     .9200824
      2 100  |    .8168449    .0542339     15.06    0.000      .7105483     .9231415
      3   0  |     .012167    .0113038      1.08    0.282      -.009988     .0343219
      3   1  |    .0124425    .0114918      1.08    0.279     -.0100811      .034966
      3   3  |     .013012    .0118767      1.10    0.273      -.010266       .03629
      3   5  |    .0136073    .0122738      1.11    0.268     -.0104489     .0376635
      3   7  |    .0142294    .0126833      1.12    0.262     -.0106294     .0390883
      3  10  |    .0152155     .013322      1.14    0.253     -.0108951     .0413261
      3  14  |    .0166356    .0142212      1.17    0.242     -.0112374     .0445086
      3  20  |    .0190132    .0156799      1.21    0.225     -.0117188     .0497453
      3  25  |    .0212466    .0170054      1.25    0.212     -.0120834     .0545766
      3  30  |     .023736     .018441      1.29    0.198     -.0124077     .0598796
      3  40  |    .0295964     .021688      1.36    0.172     -.0129112     .0721041
      3  50  |    .0368492    .0255313      1.44    0.149     -.0131913     .0868897
      3  75  |    .0631701    .0388438      1.63    0.104     -.0129622     .1393025
      3  80  |    .0702191    .0423739      1.66    0.097     -.0128323     .1532704
      3  83  |    .0747909    .0446697      1.67    0.094     -.0127601     .1623419
      3  90  |    .0865389    .0506051      1.71    0.087     -.0126453     .1857232
      3  95  |    .0959285    .0553947      1.73    0.083      -.012643     .2045001
      3  99  |    .1040855    .0595911      1.75    0.081      -.012711      .220882
      3 100  |    .1062184    .0606939      1.75    0.080     -.0127395     .2251763
      4   0  |    .1011761    .0737216      1.37    0.170     -.0433155     .2456678
      4   1  |    .1032563    .0745313      1.39    0.166     -.0428223     .2493348
      4   3  |    .1075303    .0761506      1.41    0.158      -.041722     .2567827
      4   5  |    .1119592     .077768      1.44    0.150     -.0404632     .2643816
      4   7  |    .1165467    .0793811      1.47    0.142     -.0390374     .2721307
      4  10  |    .1237333    .0817875      1.51    0.130     -.0365673     .2840339
      4  14  |    .1339044    .0849584      1.58    0.115     -.0326111     .3004199
      4  20  |    .1504777    .0895928      1.68    0.093     -.0251211     .3260764
      4  25  |    .1655474    .0932996      1.77    0.076     -.0173165     .3484113
      4  30  |    .1818033     .096825      1.88    0.060     -.0079701     .3715768
      4  40  |     .217977    .1032015      2.11    0.035      .0157058     .4202482
      4  50  |    .2590692    .1085332      2.39    0.017      .0463479     .4717904
      4  75  |     .381283     .117435      3.25    0.001      .1511146     .6114514
      4  80  |    .4083562    .1186504      3.44    0.001      .1758057     .6409068
      4  83  |    .4248829    .1193208      3.56    0.000      .1910185     .6587473
      4  90  |    .4640416    .1207365      3.84    0.000      .2274024     .7006808
      4  95  |    .4923153    .1216232      4.05    0.000      .2539383     .7306923
      4  99  |    .5149785    .1222476      4.21    0.000      .2753775     .7545794
      4 100  |    .5206383    .1223902      4.25    0.000       .280758     .7605186
-------------+----------------------------------------------------------------

. marginsplot, noci /* CIs not quite correct anyway */


Variables that uniquely identify margins: dcpct _atopt


Multiple at() options specified:


_atoption=1: dneo=0 dclox=0


_atoption=2: dneo=1 dclox=0


_atoption=3: dneo=0 dclox=1


_atoption=4: dneo=1 dclox=1


. * illustration of weighting
. margins, at(dcpct=(0(10)100)) predict(xb)

 Predictive margins                                        Number of obs    = 108
 Model VCE: OIM


Expression:  Linear prediction (log odds), predict(xb)


1._at:   dcpct   = 0
2._at:   dcpct   = 10
3._at:   dcpct   = 20
4._at:   dcpct   = 30
5._at:   dcpct   = 40
6._at:   dcpct   = 50
7._at:   dcpct   = 60
8._at:   dcpct   = 70
9._at:   dcpct   = 80
10._at:   dcpct   = 90
11._at:   dcpct   = 100

-------------+----------------------------------------------------------------
             |            Delta-method
             |     Margin    std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
         _at |
          1  |   -1.821385    .6139347     -2.97    0.003     -3.024675    -.6180956
          2  |   -1.594703    .5487433     -2.91    0.004      -2.67022    -.5191858
          3  |    -1.36802    .4854417     -2.82    0.005     -2.319469    -.4165722
          4  |   -1.141338    .4248753     -2.69    0.007     -1.974078    -.3085977
          5  |   -.9146556    .3683957     -2.48    0.013     -1.636698    -.1926133
          6  |   -.6879731    .3181865     -2.16    0.031     -1.311607     -.064339
          7  |   -.4612907    .2776705     -1.66    0.097     -1.005515     .0829335
          8  |   -.2346082    .2515752     -0.93    0.351     -.7276865     .2584701
          9  |   -.0079257    .2445612     -0.03    0.974      -.487257     .4714055
         10  |    .2187567    .2581885      0.85    0.397     -.2872834     .7247968
         11  |    .4454392    .2895571      1.54    0.124     -.1220823     1.012961
-------------+----------------------------------------------------------------

. table dneo dclox /* Stata 16: table dneo dclox, row col */


----------------------+------------------------------
                      |    Cloxacillin used on farm
                      |      no       yes       Total
----------------------+------------------------------
Neomycin used on farm |
  no                  |      33        12          45
  yes                 |      59        15          74
  Total               |      92        27         119
----------------------+------------------------------

. lincom _cons+0*dcpct+1.dclox*27/108+1.dneo*74/108 /* dcpct=0 */


 ( 1)  .6851852*[casecont]1.dneo + .25*[casecont]1.dclox + [casecont]_cons = 0


-------------+----------------------------------------------------------------
     casecont | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
         (1) |   -1.821385    .6139347     -2.97    0.003     -3.024675    -.6180956
-------------+----------------------------------------------------------------

. margins, at(dcpct=(0(10)100)) predict(xb) atmeans /* same as above */

 Adjusted predictions                                      Number of obs    = 108
 Model VCE: OIM


Expression:  Linear prediction (log odds), predict(xb)


1._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 0
2._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 10
3._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 20
4._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 30
5._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 40
6._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 50
7._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 60
8._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 70
9._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 80
10._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 90
11._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 100

-------------+----------------------------------------------------------------
             |            Delta-method
             |     Margin    std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
         _at |
          1  |   -1.821385    .6139347     -2.97    0.003     -3.024675    -.6180956
          2  |   -1.594703    .5487433     -2.91    0.004      -2.67022    -.5191858
          3  |    -1.36802    .4854417     -2.82    0.005     -2.319469    -.4165722
          4  |   -1.141338    .4248753     -2.69    0.007     -1.974078    -.3085976
          5  |   -.9146556    .3683957     -2.48    0.013     -1.636698    -.1926133
          6  |   -.6879731    .3181865     -2.16    0.031     -1.311607     -.064339
          7  |   -.4612906    .2776705     -1.66    0.097     -1.005515     .0829335
          8  |   -.2346082    .2515752     -0.93    0.351     -.7276865     .2584701
          9  |   -.0079257    .2445612     -0.03    0.974      -.487257     .4714055
         10  |    .2187567    .2581885      0.85    0.397     -.2872834     .7247968
         11  |    .4454392    .2895571      1.54    0.124     -.1220823     1.012961
-------------+----------------------------------------------------------------

. margins, at(dcpct=(0(10)100)) predict(xb) over(dneo dclox)

 Predictive margins                                        Number of obs    = 108
 Model VCE: OIM


Expression:  Linear prediction (log odds), predict(xb)


Over:  dneo dclox


1._at: 0.dneo#0.dclox
      dcpct   = 0
       0.dneo#1.dclox
      dcpct   = 0
       1.dneo#0.dclox
      dcpct   = 0
       1.dneo#1.dclox
      dcpct   = 0
2._at: 0.dneo#0.dclox
      dcpct   = 10
       0.dneo#1.dclox
      dcpct   = 10
       1.dneo#0.dclox
      dcpct   = 10
       1.dneo#1.dclox
      dcpct   = 10
3._at: 0.dneo#0.dclox
      dcpct   = 20
       0.dneo#1.dclox
      dcpct   = 20
       1.dneo#0.dclox
      dcpct   = 20
       1.dneo#1.dclox
      dcpct   = 20
4._at: 0.dneo#0.dclox
      dcpct   = 30
       0.dneo#1.dclox
      dcpct   = 30
       1.dneo#0.dclox
      dcpct   = 30
       1.dneo#1.dclox
      dcpct   = 30
5._at: 0.dneo#0.dclox
      dcpct   = 40
       0.dneo#1.dclox
      dcpct   = 40
       1.dneo#0.dclox
      dcpct   = 40
       1.dneo#1.dclox
      dcpct   = 40
6._at: 0.dneo#0.dclox
      dcpct   = 50
       0.dneo#1.dclox
      dcpct   = 50
       1.dneo#0.dclox
      dcpct   = 50
       1.dneo#1.dclox
      dcpct   = 50
7._at: 0.dneo#0.dclox
      dcpct   = 60
       0.dneo#1.dclox
      dcpct   = 60
       1.dneo#0.dclox
      dcpct   = 60
       1.dneo#1.dclox
      dcpct   = 60
8._at: 0.dneo#0.dclox
      dcpct   = 70
       0.dneo#1.dclox
      dcpct   = 70
       1.dneo#0.dclox
      dcpct   = 70
       1.dneo#1.dclox
      dcpct   = 70
9._at: 0.dneo#0.dclox
      dcpct   = 80
       0.dneo#1.dclox
      dcpct   = 80
       1.dneo#0.dclox
      dcpct   = 80
       1.dneo#1.dclox
      dcpct   = 80
10._at: 0.dneo#0.dclox
      dcpct   = 90
        0.dneo#1.dclox
      dcpct   = 90
        1.dneo#0.dclox
      dcpct   = 90
        1.dneo#1.dclox
      dcpct   = 90
11._at: 0.dneo#0.dclox
      dcpct   = 100
        0.dneo#1.dclox
      dcpct   = 100
        1.dneo#0.dclox
      dcpct   = 100
        1.dneo#1.dclox
      dcpct   = 100

---------------+----------------------------------------------------------------
               |            Delta-method
               |     Margin    std. err.       z    P>|z|      [95% con f. interval]
---------------+----------------------------------------------------------------
_at#dneo#dclox |
      1#no#no  |   -2.984272    .7722467     -3.86    0.000     -4.497848    -1.470697
     1#no#yes  |   -4.396788    .9404953     -4.67    0.000     -6.240125    -2.553452
     1#yes#no  |   -.7717085    .5987154     -1.29    0.197     -1.945169     .4017521
    1#yes#yes  |   -2.184225    .8106662     -2.69    0.007     -3.773101    -.5953479
      2#no#no  |    -2.75759    .7219825     -3.82    0.000      -4.17265     -1.34253
     2#no#yes  |   -4.170106    .8890788     -4.69    0.000     -5.912668    -2.427544
     2#yes#no  |    -.545026    .5378343     -1.01    0.311     -1.599162     .5091099
    2#yes#yes  |   -1.957542     .754335     -2.60    0.009     -3.436012    -.4790726
      3#no#no  |   -2.530907    .6756357     -3.75    0.000     -3.855129    -1.206686
     3#no#yes  |   -3.943424    .8406675     -4.69    0.000     -5.591102    -2.295745
     3#yes#no  |   -.3183436    .4800024     -0.66    0.507     -1.259131     .6224439
    3#yes#yes  |    -1.73086    .7008523     -2.47    0.014     -3.104505    -.3572144
      4#no#no  |   -2.304225    .6340656     -3.63    0.000     -3.546971    -1.061479
     4#no#yes  |   -3.716741      .79581     -4.67    0.000       -5.2765    -2.156982
     4#yes#no  |   -.0916611     .426462     -0.21    0.830     -.9275113      .744189
    4#yes#yes  |   -1.504177    .6509204     -2.31    0.021     -2.779958    -.2283966
      5#no#no  |   -2.077543    .5982691     -3.47    0.001     -3.250128    -.9049568
     5#no#yes  |   -3.490059    .7551398     -4.62    0.000     -4.970105    -2.010012
     5#yes#no  |    .1350213     .379036      0.36    0.722     -.6078756     .8779183
    5#yes#yes  |   -1.277495    .6054187     -2.11    0.035     -2.464094    -.0908958
      6#no#no  |    -1.85086     .569336     -3.25    0.001     -2.966738    -.7349821
     6#no#yes  |   -3.263376    .7193676     -4.54    0.000     -4.673311    -1.853442
     6#yes#no  |    .3617038    .3402906      1.06    0.288     -.3052536     1.028661
    6#yes#yes  |   -1.050812    .5654177     -1.86    0.063     -2.159011     .0573861
      7#no#no  |   -1.624178    .5483539     -2.96    0.003     -2.698932    -.5494237
     7#no#yes  |   -3.036694    .6892563     -4.41    0.000     -4.387611    -1.685776
     7#yes#no  |    .5883862    .3134615      1.88    0.061     -.0259869     1.202759
    7#yes#yes  |   -.8241298    .5321593     -1.55    0.121     -1.867143     .2188833
      8#no#no  |   -1.397495    .5362569     -2.61    0.009     -2.448539    -.3464509
     8#no#yes  |   -2.810011    .6655747     -4.22    0.000     -4.114514    -1.505509
     8#yes#no  |    .8150687    .3017439      2.70    0.007      .2236615     1.406476
    8#yes#yes  |   -.5974473    .5069722     -1.18    0.239     -1.591095        .3962
      9#no#no  |   -1.170813    .5336496     -2.19    0.028     -2.216747    -.1248787
     9#no#yes  |   -2.583329     .649027     -3.98    0.000     -3.855398    -1.311259
     9#yes#no  |    1.041751     .306874      3.39    0.001      .4402891     1.643213
    9#yes#yes  |   -.3707649    .4910999     -0.75    0.450     -1.333303     .5917732
     10#no#no  |   -.9441303    .5406693     -1.75    0.081     -2.003823     .1155621
    10#no#yes  |   -2.356646    .6401668     -3.68    0.000      -3.61135    -1.101943
    10#yes#no  |    1.268434    .3280623      3.87    0.000      .6254433     1.911424
   10#yes#yes  |   -.1440824    .4854568     -0.30    0.767      -1.09556     .8073953
     11#no#no  |   -.7174478    .5569521     -1.29    0.198     -1.809054     .3741583
    11#no#yes  |   -2.129964    .6393135     -3.33    0.001     -3.382995    -.8769324
    11#yes#no  |    1.495116    .3625038      4.12    0.000      .7846216     2.205611
   11#yes#yes  |       .0826    .4903962      0.17    0.866     -.8785588     1.043759
---------------+----------------------------------------------------------------

. di ((-2.984272)*22+(-4.396788)*12+(-.7717085)*59+(-2.184225)*15)/108 /* dcpct=0 again */
-1.8213853

. margins, at(dcpct=(0(10)100)) atmeans /* backtransformed */

 Adjusted predictions                                      Number of obs    = 108
 Model VCE: OIM


Expression:  Pr(casecont), predict()


1._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 0
2._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 10
3._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 20
4._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 30
5._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 40
6._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 50
7._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 60
8._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 70
9._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 80
10._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 90
11._at:   0.dneo   = .3148148   (mean)
  1.dneo   = .6851852   (mean)
  0.dclox   = .75   (mean)
  1.dclox   = .25   (mean)
  dcpct   = 100

-------------+----------------------------------------------------------------
             |            Delta-method
             |     Margin    std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
         _at |
          1  |    .1392677    .0735937      1.89    0.058     -.0049733     .2835087
          2  |    .1687233    .0769644      2.19    0.028      .0178758     .3195707
          3  |    .2029399    .0785228      2.58    0.010      .0490381     .3568416
          4  |    .2420748    .0779538      3.11    0.002      .0892881     .3948615
          5  |    .2860481    .0752355      3.80    0.000      .1385893     .4335069
          6  |    .3344841    .0708297      4.72    0.000      .1956604     .4733079
          7  |    .3866797    .0658519      5.87    0.000      .2576123     .5157471
          8  |    .4416155    .0620362      7.12    0.000      .3200267     .5632043
          9  |    .4980186    .0611394      8.15    0.000      .3781877     .6178495
         10  |    .5544721     .063781      8.69    0.000      .4294636     .6794806
         11  |    .6095543     .068914      8.85    0.000      .4744854     .7446232
-------------+----------------------------------------------------------------

. di invlogit(-1.821385) /* dcpct=0, transformed to probability scale */
.13926777

. * weighting on probability scale
. margins, at(dcpct=(0(10)100)) /* not the same! */

 Predictive margins                                        Number of obs    = 108
 Model VCE: OIM


Expression:  Pr(casecont), predict()


1._at:   dcpct   = 0
2._at:   dcpct   = 10
3._at:   dcpct   = 20
4._at:   dcpct   = 30
5._at:   dcpct   = 40
6._at:   dcpct   = 50
7._at:   dcpct   = 60
8._at:   dcpct   = 70
9._at:   dcpct   = 80
10._at:   dcpct   = 90
11._at:   dcpct   = 100

-------------+----------------------------------------------------------------
             |            Delta-method
             |     Margin    std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
         _at |
          1  |    .1979002    .0842364      2.35    0.019         .0328     .3630005
          2  |    .2315299    .0825239      2.81    0.005       .069786     .3932737
          3  |    .2680634    .0785496      3.41    0.001       .114109     .4220178
          4  |    .3070171    .0726128      4.23    0.000      .1646987     .4493355
          5  |    .3477956    .0653188      5.32    0.000      .2197731     .4758182
          6  |    .3897493    .0575728      6.77    0.000      .2769088     .5025898
          7  |    .4322352     .050553      8.55    0.000      .3331532     .5313172
          8  |    .4746683     .045601     10.41    0.000       .385292     .5640446
          9  |    .5165521    .0438292     11.79    0.000      .4306484     .6024558
         10  |    .5574866    .0454685     12.26    0.000      .4683699     .6466033
         11  |     .597158    .0497083     12.01    0.000      .4997316     .6945844
-------------+----------------------------------------------------------------

. margins, at(dcpct=(0(10)100)) expression(invlogit(predict(xb))) /* same as preceding line */

 Predictive margins                                        Number of obs    = 108
 Model VCE: OIM


Expression:  invlogit(predict(xb))


1._at:   dcpct   = 0
2._at:   dcpct   = 10
3._at:   dcpct   = 20
4._at:   dcpct   = 30
5._at:   dcpct   = 40
6._at:   dcpct   = 50
7._at:   dcpct   = 60
8._at:   dcpct   = 70
9._at:   dcpct   = 80
10._at:   dcpct   = 90
11._at:   dcpct   = 100

-------------+----------------------------------------------------------------
             |            Delta-method
             |     Margin    std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
         _at |
          1  |    .1979002    .0842364      2.35    0.019         .0328     .3630005
          2  |    .2315299    .0825239      2.81    0.005       .069786     .3932737
          3  |    .2680634    .0785496      3.41    0.001       .114109     .4220178
          4  |    .3070171    .0726128      4.23    0.000      .1646987     .4493355
          5  |    .3477956    .0653188      5.32    0.000      .2197731     .4758182
          6  |    .3897493    .0575728      6.77    0.000      .2769088     .5025898
          7  |    .4322352     .050553      8.55    0.000      .3331532     .5313172
          8  |    .4746683     .045601     10.41    0.000       .385292     .5640446
          9  |    .5165521    .0438292     11.79    0.000      .4306484     .6024558
         10  |    .5574866    .0454685     12.26    0.000      .4683699     .6466033
         11  |     .597158    .0497083     12.01    0.000      .4997316     .6945844
-------------+----------------------------------------------------------------

. margins, at(dcpct=(0(10)100)) predict(pr) /* same as preceding line */

 Predictive margins                                        Number of obs    = 108
 Model VCE: OIM


Expression:  Pr(casecont), predict(pr)


1._at:   dcpct   = 0
2._at:   dcpct   = 10
3._at:   dcpct   = 20
4._at:   dcpct   = 30
5._at:   dcpct   = 40
6._at:   dcpct   = 50
7._at:   dcpct   = 60
8._at:   dcpct   = 70
9._at:   dcpct   = 80
10._at:   dcpct   = 90
11._at:   dcpct   = 100

-------------+----------------------------------------------------------------
             |            Delta-method
             |     Margin    std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
         _at |
          1  |    .1979002    .0842364      2.35    0.019         .0328     .3630005
          2  |    .2315299    .0825239      2.81    0.005       .069786     .3932737
          3  |    .2680634    .0785496      3.41    0.001       .114109     .4220178
          4  |    .3070171    .0726128      4.23    0.000      .1646987     .4493355
          5  |    .3477956    .0653188      5.32    0.000      .2197731     .4758182
          6  |    .3897493    .0575728      6.77    0.000      .2769088     .5025898
          7  |    .4322352     .050553      8.55    0.000      .3331532     .5313172
          8  |    .4746683     .045601     10.41    0.000       .385292     .5640446
          9  |    .5165521    .0438292     11.79    0.000      .4306484     .6024558
         10  |    .5574866    .0454685     12.26    0.000      .4683699     .6466033
         11  |     .597158    .0497083     12.01    0.000      .4997316     .6945844
-------------+----------------------------------------------------------------

. margins, at(dcpct=(0(10)100)) over(dneo dclox)

 Predictive margins                                        Number of obs    = 108
 Model VCE: OIM


Expression:  Pr(casecont), predict()


Over:  dneo dclox


1._at: 0.dneo#0.dclox
      dcpct   = 0
       0.dneo#1.dclox
      dcpct   = 0
       1.dneo#0.dclox
      dcpct   = 0
       1.dneo#1.dclox
      dcpct   = 0
2._at: 0.dneo#0.dclox
      dcpct   = 10
       0.dneo#1.dclox
      dcpct   = 10
       1.dneo#0.dclox
      dcpct   = 10
       1.dneo#1.dclox
      dcpct   = 10
3._at: 0.dneo#0.dclox
      dcpct   = 20
       0.dneo#1.dclox
      dcpct   = 20
       1.dneo#0.dclox
      dcpct   = 20
       1.dneo#1.dclox
      dcpct   = 20
4._at: 0.dneo#0.dclox
      dcpct   = 30
       0.dneo#1.dclox
      dcpct   = 30
       1.dneo#0.dclox
      dcpct   = 30
       1.dneo#1.dclox
      dcpct   = 30
5._at: 0.dneo#0.dclox
      dcpct   = 40
       0.dneo#1.dclox
      dcpct   = 40
       1.dneo#0.dclox
      dcpct   = 40
       1.dneo#1.dclox
      dcpct   = 40
6._at: 0.dneo#0.dclox
      dcpct   = 50
       0.dneo#1.dclox
      dcpct   = 50
       1.dneo#0.dclox
      dcpct   = 50
       1.dneo#1.dclox
      dcpct   = 50
7._at: 0.dneo#0.dclox
      dcpct   = 60
       0.dneo#1.dclox
      dcpct   = 60
       1.dneo#0.dclox
      dcpct   = 60
       1.dneo#1.dclox
      dcpct   = 60
8._at: 0.dneo#0.dclox
      dcpct   = 70
       0.dneo#1.dclox
      dcpct   = 70
       1.dneo#0.dclox
      dcpct   = 70
       1.dneo#1.dclox
      dcpct   = 70
9._at: 0.dneo#0.dclox
      dcpct   = 80
       0.dneo#1.dclox
      dcpct   = 80
       1.dneo#0.dclox
      dcpct   = 80
       1.dneo#1.dclox
      dcpct   = 80
10._at: 0.dneo#0.dclox
      dcpct   = 90
        0.dneo#1.dclox
      dcpct   = 90
        1.dneo#0.dclox
      dcpct   = 90
        1.dneo#1.dclox
      dcpct   = 90
11._at: 0.dneo#0.dclox
      dcpct   = 100
        0.dneo#1.dclox
      dcpct   = 100
        1.dneo#0.dclox
      dcpct   = 100
        1.dneo#1.dclox
      dcpct   = 100

---------------+----------------------------------------------------------------
               |            Delta-method
               |     Margin    std. err.       z    P>|z|      [95% con f. interval]
---------------+----------------------------------------------------------------
_at#dneo#dclox |
      1#no#no  |    .0481415    .0353873      1.36    0.174     -.0212164     .1174994
     1#no#yes  |     .012167    .0113038      1.08    0.282      -.009988     .0343219
     1#yes#no  |    .3161096    .1294329      2.44    0.015      .0624258     .5697934
    1#yes#yes  |    .1011761    .0737216      1.37    0.170     -.0433155     .2456678
      2#no#no  |    .0596594    .0405034      1.47    0.141     -.0197257     .1390445
     2#no#yes  |    .0152155     .013322      1.14    0.253     -.0108951     .0413261
     2#yes#no  |    .3670192    .1249476      2.94    0.003      .1221264     .6119119
    2#yes#yes  |    .1237333    .0817875      1.51    0.130     -.0365673     .2840339
      3#no#no  |    .0737197    .0461358      1.60    0.110     -.0167049     .1641442
     3#no#yes  |    .0190132    .0156799      1.21    0.225     -.0117188     .0497453
     3#yes#no  |    .4210795    .1170109      3.60    0.000      .1917423     .6504167
    3#yes#yes  |    .1504777    .0895928      1.68    0.093     -.0251211     .3260764
      4#no#no  |    .0907736    .0523318      1.73    0.083     -.0117949     .1933422
     4#no#yes  |     .023736     .018441      1.29    0.198     -.0124077     .0598796
     4#yes#no  |    .4771007    .1063919      4.48    0.000      .2685765      .685625
    4#yes#yes  |    .1818033     .096825      1.88    0.060     -.0079701     .3715768
      5#no#no  |    .1112988    .0591756      1.88    0.060     -.0046833     .2272809
     5#no#yes  |    .0295964     .021688      1.36    0.172     -.0129112     .0721041
     5#yes#no  |    .5337041    .0943284      5.66    0.000      .3488238     .7185845
    5#yes#yes  |     .217977    .1032015      2.11    0.035      .0157058     .4202482
      6#no#no  |    .1357719    .0668047      2.03    0.042      .0048371     .2667067
     6#no#yes  |    .0368492    .0255313      1.44    0.149     -.0131913     .0868897
     6#yes#no  |    .5894528    .0823497      7.16    0.000      .4280503     .7508553
    6#yes#yes  |    .2590692    .1085332      2.39    0.017      .0463479     .4717904
      7#no#no  |    .1646295    .0754133      2.18    0.029      .0168222     .3124368
     7#no#yes  |    .0457954    .0301193      1.52    0.128     -.0132372     .1048281
     7#yes#no  |    .6429948    .0719559      8.94    0.000      .5019639     .7840257
    7#yes#yes  |    .3048877    .1127812      2.70    0.007      .0838407     .5259347
      8#no#no  |    .1982139    .0852247      2.33    0.020      .0311765     .3652512
     8#no#yes  |    .0567856    .0356488      1.59    0.111     -.0130848      .126656
     8#yes#no  |    .6931886    .0641743     10.80    0.000      .5674091      .818968
    8#yes#yes  |    .3549279    .1160734      3.06    0.002      .1274283     .5824275
      9#no#no  |    .2367081    .0964184      2.46    0.014      .0477315     .4256847
     9#no#yes  |    .0702191    .0423739      1.66    0.097     -.0128323     .1532704
     9#yes#no  |    .7391878     .059162     12.49    0.000      .6232324     .8551431
    9#yes#yes  |    .4083562    .1186504      3.44    0.001      .1758057     .6409068
     10#no#no  |    .2800668    .1090148      2.57    0.010      .0664017     .4937319
    10#no#yes  |    .0865389    .0506051      1.71    0.087     -.0126453     .1857232
    10#yes#no  |    .7804745    .0562082     13.89    0.000      .6703084     .8906406
   10#yes#yes  |    .4640416    .1207365      3.84    0.000      .2274024     .7006808
     11#no#no  |    .3279552    .1227526      2.67    0.008      .0873646     .5685459
    11#no#yes  |    .1062184    .0606939      1.75    0.080     -.0127395     .2251763
    11#yes#no  |    .8168449    .0542339     15.06    0.000      .7105483     .9231415
   11#yes#yes  |    .5206383    .1223902      4.25    0.000       .280758     .7605186
---------------+----------------------------------------------------------------

. di (.0481415*22+.012167*12+.3161096*59+.1011761*15)/108 /* dcpct=0, weighted at probability scale */
.19790023

.
end of do-file

. exit, clear