Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Re-re-post: Stata 11 - Factor variables in a regression command
From
Richard Williams <[email protected]>
To
[email protected]
Subject
Re: Re-re-post: Stata 11 - Factor variables in a regression command
Date
Sat, 01 May 2010 11:20:05 -0500
At 01:42 AM 5/1/2010, Michael Norman Mitchell wrote:
Dear Ricardo
The command
. logistic y a#b
includes just the interaction of "a by b", and does not include
the main effect of a, nor the main effect of b. By contrast, the command
. logistic y a##b
includes the main effect of a, the main effect of b, as well as
the a by b interaction. It is equivalent to typing
. logistic y a#b a b
Incidentally, if the variables are continuous, rather than
categorical, Mike's description is right, i.e. c.a#c.b only enters
the interaction term of a*b and not the lower level effects. But by
default, Stata assumes the crossed variables are categorical unless
you indicate otherwise, and the # and ## notations produce different
parameterizations of the same model.
These factor variables are nice but make sure you understand what
parameterization you are getting and how to interpret it!!!
Personally I think there is much to be said for explicitly including
the main effects so I can make sure they are there and to make my
commands easier to read, i.e. I prefer
logit y i.a i.b a#b
over
logit y a##b
The following illustrates how the c. notation changes things. In the
first syntax, you only get the interaction term, in the other two you
get both the interaction and the main effects.
. use "http://www.indiana.edu/~jslsoc/stata/spex_data/ordwarm2.dta", clear
(77 & 89 General Social Survey)
. logit warmlt2 c.yr89#c.male, nolog
Logistic regression Number of obs = 2293
LR chi2(1) = 7.81
Prob > chi2 = 0.0052
Log likelihood = -880.00359 Pseudo R2 = 0.0044
------------------------------------------------------------------------------
warmlt2 | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
c.yr89#|
c.male | -.497305 .186906 -2.66 0.008 -.863634 -.130976
|
_cons | -1.829973 .0666787 -27.44 0.000 -1.960661 -1.699285
------------------------------------------------------------------------------
. logit warmlt2 c.yr89##c.male, nolog
Logistic regression Number of obs = 2293
LR chi2(3) = 64.74
Prob > chi2 = 0.0000
Log likelihood = -851.54241 Pseudo R2 = 0.0366
------------------------------------------------------------------------------
warmlt2 | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | -1.295833 .229115 -5.66 0.000 -1.74489 -.8467762
male | .1816812 .1431068 1.27 0.204 -.098803 .4621655
|
c.yr89#|
c.male | .4542502 .3050139 1.49 0.136 -.1435661 1.052066
|
_cons | -1.667376 .1021154 -16.33 0.000 -1.867518 -1.467233
------------------------------------------------------------------------------
. logit warmlt2 yr89 male c.yr89#c.male, nolog
Logistic regression Number of obs = 2293
LR chi2(3) = 64.74
Prob > chi2 = 0.0000
Log likelihood = -851.54241 Pseudo R2 = 0.0366
------------------------------------------------------------------------------
warmlt2 | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | -1.295833 .229115 -5.66 0.000 -1.74489 -.8467762
male | .1816812 .1431068 1.27 0.204 -.098803 .4621655
|
c.yr89#|
c.male | .4542502 .3050139 1.49 0.136 -.1435661 1.052066
|
_cons | -1.667376 .1021154 -16.33 0.000 -1.867518 -1.467233
------------------------------------------------------------------------------
.
-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
HOME: (574)289-5227
EMAIL: [email protected]
WWW: http://www.nd.edu/~rwilliam
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/