Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Stata list example - use of the margins command

From   Peter Baade <>
To   "" <>
Subject   st: RE: Stata list example - use of the margins command
Date   Fri, 9 Dec 2011 08:42:58 +1000


Thanks for responding. However on further examination of nlcom command, and reading the online stata manual, I'm not sure that nlcom is the idea method for calculating confidence intervals for odds ratios following the margins command. This is noted on page 1208 of the stata manual (nlcom), in which they say that while the exponential coefficients are identical, the calculated confidence intervals are not, probably due to the nlcom using asymptotically-equivalent calculations for the CIs.

In the example below (with a reduced sample size) I generate the odds ratios using three methods, margins with nlcom, tabodds, and stratified logistic regression. While the ORs and standard errors are very similar, nlcom's confidence intervals seem to be incorrect.


*********** Begin example ******************
. sysuse nlsw88, clear
(NLSW, 1988 extract)

. gen byte high_occ = occupation < 3 if occupation < .
(9 missing values generated)

. gen byte black = race == 2 if race < .

. drop if race==3
(26 observations deleted)

. drop if _n > 1000
(1220 observations deleted)

. quietly logistic high_occ i.race##i.collgrad
. quietly margins, over(race collgrad) expression(exp(xb())) post

. ** Odds ratio (black:white) when collgrad=1
. nlcom (_b[2.race#1.collgrad] / _b[1.race#1.collgrad] )

       _nl_1:  _b[2.race#1.collgrad] / _b[1.race#1.collgrad]

             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
       _nl_1 |   .8181818   .3766025     2.17   0.030     .0800545    1.556309

. ** Odds ratio (black:white) when collgrad=1
. tabodds high_occ race if collgrad==1, or

        race |  Odds Ratio       chi2       P>chi2     [95% Conf. Interval]
       white |    1.000000          .           .              .          .
       black |    0.818182       0.19       0.6631      0.331220   2.021078
Test of homogeneity (equal odds): chi2(1)  =     0.19
                                  Pr>chi2  =   0.6631

Score test for trend of odds:     chi2(1)  =     0.19
                                  Pr>chi2  =   0.6631

. ** Odds ratio (black:white) when collgrad=1
. logistic high_occ i.race if collgrad==1

Logistic regression                               Number of obs   =        251
                                                  LR chi2(1)      =       0.19
                                                  Prob > chi2     =     0.6618
Log likelihood = -173.54746                       Pseudo R2       =     0.0006

    high_occ | Odds Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
      2.race |   .8181819   .3766026    -0.44   0.663     .3319316    2.016746

**************** End Example *****************

-----Original Message-----
From: Maarten Buis [] 
Sent: Thursday, 8 December 2011 7:21 PM
Subject: Stata list example - use of the margins command

--- Peter Baade wrote me privately:
> I noticed that you posted the following example on the Stata list in 
> May this year. 
> <>
> I was wondering if I could ask you one question

You can, but convention on Statalist is that these questions are asked on the list rather than privately. If you found something strange than odds are that others will also find that to be the case, and would thus appreciate an answer as well. It also has advantages for you, because it regularly happens that others participate in the discussion contributing another point of view or pointing out mistakes or ommisions in my answer. This is discussed in the Statalist FAQ:
<> So I forwarded this messages to statalist.

> when you used the "di" command below, could I use the nlcom command to get confidence intervals? I've used this and get very wide intervals, inconsistent with the p-value.

Below is an adaptation of the example you refer to, replacing -di- with -nlcom-. The p-value in -nlcom- is in this case useless as it tests the hypothesis that the odds ratio is 0 rather than the meaningfull hypothesis that the odds ratio is 1.

You can also see the confidence interval produced by -nlcom- is somewhat different from the confidence interval produced by -logit- even though the coefficient and the standard error match exactly. The reason for that is explained here:

*------------------------ begin example ------------------------------------
sysuse nlsw88, clear
gen byte high_occ = occupation < 3 if occupation < .
gen byte black = race == 2 if race < .
drop if race == 3
gen byte baseline = 1

sum ttl_exp
gen c_ttl_exp = ttl_exp - r(mean)

// fix at average ttl_exp (12.5 years)

logit high_occ black##collgrad c_ttl_exp baseline, or nocons

margins, over(black collgrad) expression(exp(xb())) ///
         at(c_ttl_exp = 0) post

nlcom (_b[] / _b[] ) / ///
      (_b[] / _b[])
*-------------------------- end example ------------------------------------
(For more on examples I sent to the Statalist see: )

Hope this helps,

Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen


Please consider our environment before printing this email

This email and any attachments is intended for the named recipient(s) only and may contain privileged and confidential information. If you have received this email in error, please inform the sender and delete this email and any copies from your computer network. If you are not the intended recipient of this email, any unauthorised use is expressly prohibited. It is your responsibility to check any attachments for viruses and defects before opening or sending them on.

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index