Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: xi: and if


From   Jonathan Sterne <[email protected]>
To   [email protected]
Subject   st: xi: and if
Date   Tue, 27 Jul 2004 14:24:37 +0100

A colleague and I were recently caught by the way that xi: interacts with if clauses. In the following, the whole dataset contains a value 0 for variable e1swabtype, but the subset that we wish to deal with does not. Because xi: creates indicator variables corresponding to every value in the dataset, not every value to be processed by the logistic command, logistic has to pick an indicator to be dropped, which it does automatically. Unfortunately for us, it dropped the indicator for level 2, leaving the results of the logistic regression the opposite way round to the way that we would have expected (i.e. the way that we got when we dropped the unwanted observations, then ran a logistic regression.)

Most of the time, we think of these two options (run the command on a subgroup using -if- or drop the observations not in the subgroup) as interchangeable. Is there a good reason that xi: does not respect the if clause?

Jonathan Sterne


. tab e1swabtype

e1swab type | Freq. Percent Cum.
------------+-----------------------------------
0 | 9,966 51.01 51.01
1 | 337 1.73 52.74
2 | 9,233 47.26 100.00
------------+-----------------------------------
Total | 19,536 100.00

. tab e1swabtype if e0gppracticeid=="L81022" & e0sex==2

e1swab type | Freq. Percent Cum.
------------+-----------------------------------
1 | 337 49.93 49.93
2 | 338 50.07 100.00
------------+-----------------------------------
Total | 675 100.00

. tab e1swabtype responder1 if e0gppracticeid=="L81022" & e0sex==2

e1swab | responder1
type | 0 1 | Total
-----------+----------------------+----------
1 | 223 114 | 337
2 | 239 99 | 338
-----------+----------------------+----------
Total | 462 213 | 675


. xi: logistic responder1 i.e1swabtype [pw=sampweight] ///

    if e0gppracticeid=="L81022" & e0sex==2
i.e1swabtype _Ie1swabtyp_0-2 (naturally coded; _Ie1swabtyp_0 omitted)

note: _Ie1swabtyp_2 dropped due to collinearity

Logistic regression Number of obs = 675
Wald chi2(1) = 4.98
Prob > chi2 = 0.0257
Log pseudo-likelihood = -419.26431 Pseudo R2 = 0.0091

---------------------------------------------------------------------------
---
| Robust
responder1 | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+-------------------------------------------------------------
---
_Ie1swabty~1 | 1.583557 .3262572 2.23 0.026 1.057456 2.371402
---------------------------------------------------------------------------
---

.
. keep if e0gppracticeid=="L81022" & e0sex==2
(19098 observations deleted)

. xi: logistic responder1 i.e1swabtype [pw=sampweight] ///

    if e0gppracticeid=="L81022" & e0sex==2
i.e1swabtype _Ie1swabtyp_1-2 (naturally coded; _Ie1swabtyp_1 omitted)

Logistic regression Number of obs = 675
Wald chi2(1) = 4.98
Prob > chi2 = 0.0257
Log pseudo-likelihood = -419.26431 Pseudo R2 = 0.0091

---------------------------------------------------------------------------
---
| Robust
responder1 | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+-------------------------------------------------------------
---
_Ie1swabty~2 | .6314897 .1301046 -2.23 0.026 .4216915 .9456657
---------------------------------------------------------------------------
---




----------------------

Jonathan Sterne

Department of Social Medicine
University of Bristol
Canynge Hall
Whiteladies Road
Bristol BS8 2PR
UK

E-mail: [email protected]
web: www.epi.bris.ac.uk

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index