Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: st: Re: using the test command within group

 From Rebecca Pope To statalist@hsphsun2.harvard.edu Subject Re: st: Re: using the test command within group Date Sun, 3 Mar 2013 15:12:18 -0600

```A Chow test is a test for equality of coefficients for all covariates
in the model across groups, not within. That said, I think Joseph's
proposed solution is largely correct. However, embedded in Jordan's
question are several assumptions that should be obviated before
discussing syntax. The phrase "equally strong predictors" puzzles me,
but what Jordan's subsequent text suggests is that "strong" refers to
the magnitude of the coefficient estimate. Thus, the implicit
assumption is that strength of association between the dependent and
any independent variable is best measured by the coefficient estimate
alone. If we accept this, we must also assume that x1 and x2 are
measured on the same scale. To see why, just look at Stata's first
example for -xtmelogit-.

xtmelogit c_use urban age child* || district:

"age" is mean-centered and continuous; the coefficient estimate is
-0.03. All other coefficient estimates are for binary covariates, to
which we cannot directly compare the raw coefficient of age. This
simple comparison can be used to illustrate another assumption: the
direction of the effects should be the same if we are working under
the coefficient as measure of association. Let's assume for the sake
of argument that instead of being positive, the coefficient on
"child3" was negative. It would be hard to argue, looking at the
results, that "child2" was a stronger predictor of birth control use
than "child3" in this imaginary situation, they just had opposing
effects.

So, these are our starting assumptions then: (1) strength =
coefficient magnitude, (2) same scale, (3) same expected direction of
effect. If we accept all of these assumptions, Joseph has correctly
pointed out that an interaction is the best way to approach the
problem. However, his code needs a slight modification. Jordan needs
to test b1 and b2 for _both_ groups in order to adequately address the
hypothesis of b1=b2 only in group 2. Thus, one step beyond Joseph's
solution is needed.

Keeping with the Bangladesh contraceptive data, let "urban" be the
group variable, x1=child2 and x2=child3. Jordan hasn't told us
anything about specifying different models for the two groups, so
we'll assume for now that the only interest is in separate effects of
x1 and x2 (i.e. any other coefficients constrained to be equal between
the two groups).

xtmelogit c_use age child1 i.child2##i.urban i.child3##i.urban ||
district:, nolog

The first observation is that the interaction terms aren't
significant, so no separate group effects exist here, but let's
pretend we didn't notice that...
The group 1 (rural)-specific effects are the main effects for child2
and child3. To see the group 2 effects, do exactly what Joseph's code
shows:
lincom _b[1.child2]+_b[1.child2#1.urban]
lincom _b[1.child3]+_b[1.child3#1.urban]

Test with:
test ((_b[1.child2]+_b[1.child2#1.urban])=(_b[1.child3]+_b[1.child3#1.urban]))
(_b[1.child2]=_b[1.child3]), mtest

Regards,
Rebecca

On Sun, Mar 3, 2013 at 1:05 AM, Joseph Coveney <stajc2@gmail.com> wrote:
> Jordan Silberman wrote:
>
> I have a mixed-effects logistic model (xtmelogit) that includes a
> group variable (grp = 1 or 2) and 2 predictors (x1 and x2). I'd like
> to use the test command (or perhaps some other command) to test the
> hypothesis that x1 and x2 are equally strong predictors of the
> dependent variable for subjects in group 2 only. It would of course be
> easy to do this with the test command if I wanted to test this
> hypothesis for the full sample (test x1 = x2). But I can't find a way
> to test this hypothesis for just one level of the group variable.
> Suggestions?
>
> --------------------------------------------------------------------------------
>
> It sounds like the logistic analogue of what I believe econometricians call a
> Chow test.  If so, then take a look at
> http://www.stata.com/support/faqs/statistics/computing-chow-statistic/ .
>
> If you want to test the equality of the regression coefficients for group 2,
> couldn't you add interaction terms and then test?  Something like:
>
>     xtmelogit response i.grp##c.(x1 x2) || subjects:
>     test (_b[x1] + _b[2.grp#x1]) = (_b[x2] + _b[2.grp#x2])
>
> If yours are observational data, then I'm guessing that the coefficients would
> have the usual logistic regression sensitivity to omitted variables.
>
> Joseph Coveney
>
> clear *
> set more off
> set seed `=date("2013-03-03", "YMD")'
> set seed0 `=date("2013-03-03", "YMD")'
> quietly set obs 200
> generate byte grp = 1 + (_n > _N / 2)
>
> generate int subject = _n
> generate double x1 = runiform()
> generate double x2 = runiform()
> generate double xb = x1 - x2
> quietly replace xb = x1 + x2 if grp == 2
>
> generate k = 50
> quietly expand k
>
> genbinomial response, xbeta(xb) // -findit genbinomial-
> quietly compress
>
> xtgee response c.(x1 x2) if grp == 2, i(subject) family(binomial) nolog
> xtgee response i.grp##c.(x1 x2), i(subject) family(binomial) nolog
> lincom _b[x1] + _b[2.grp#x1]
> lincom _b[x2] + _b[2.grp#x2]
>
> test (_b[x1] + _b[2.grp#x1]) = (_b[x2] + _b[2.grp#x2])
>
> exit
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```