Statalist


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

Re: st: Random Coefficients in Crossed-Effects Models


From   [email protected] (Roberto G. Gutierrez, StataCorp)
To   [email protected]
Subject   Re: st: Random Coefficients in Crossed-Effects Models
Date   Thu, 10 Dec 2009 10:41:10 -0600

Andrew Spiegelman <[email protected]> asks about fitting a mixed model with
crossed random coefficients in addition to the standard crossed random
intercepts:

> I am using Stata MP version 10 in Windows.  I would like to run a
> crossed-effects model using xtmixed.  Further, I would like this model to
> have random coefficients in addition to the random intercepts it normally
> produces.  For example, a basic crossed-effects model looks like

> xtmixed depvar indepvar || _all: R.groupvar1 || groupvar2:

> where groupvar1 and groupvar2 are the two groups I would like to estimate
> random effects for but would like them not to be nested within each other
> (hence why I wish to use a crossed-effects model).  But this model does not
> appear to permit the use of random coefficients the way the more basic
> xtmixed command does:

> xtmixed depvar indepvar || groupvar: indepvar

> In the above case my output will contain a random intercept organized by the
> group groupvar and will also have a random coefficient on indepvar
> associated with groupvar.

> My question is, how can I get the random coefficient into a crossed-effects
> model?  Specifically, I'd like the random coefficient to occur in BOTH
> groups.  

[...]

Such a model is not straightforward in -xtmixed-, but it is possible to do
this if you manually replicate the work that the "R." factor notation does for
you.

Begin by first generating a set of dummy variables that identify the groups
defined by -groupvar1-:

   . tabulate groupvar1, gen(id1_)

Then, generate interactions of these dummy variables with the independent
variable on which you want to have random coefficients at the levels of 
-groupvar1-:

   . foreach var of varlist id1_* { 
             gen `var'Xindepvar = `var' * indepvar
     }

Finally, now that you have the variables -id1_*Xindepvar-, you can include
these within -xtmixed- as an additional random-effects term at the "_all:" 
level:

   . xtmixed depvar indepvar || _all:R.groupvar              
                             || _all:id1_*Xindepvar, noconstant cov(identity)
			     || groupvar2: indepvar

That should do the trick.

--Bobby
[email protected]
*
*   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/



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