Dear all,
I would like to fit a random effects model with a categorical predictor variable and random coefficients for this categorical predictor variable--pretty much like the following:
The model I want to fit looks like this:
Just that the coefficients for the categorical variable are fixed in this case above. My intuition as to how to set them to random is the following:
This however yields the error message "must use R. when specifying factor variables in random-effects equations, r(198)." From this I take that the command should look like this:
This however yields the error message: "unstructured covariance structure not allowed for factor variables, r(198)." Given that I don't know what the r-operator is doing in the first place, I don't mind not insisting on an unstructured covariance structure and go with:
This then does give me a result, yet now the variance component for the intercept is gone and I do not know what the variance component I get instead -- var(R.time) -- is supposed to represent.
My question now is: What does the r-operator do? Is it described anywhere in the documentation (sorry, I couldn't find it myself)?
As a bonus question:
I know that what I wanted to do initially -- a random coefficient model for a categorical predictor -- can be obtained when not using factor variables:
(well, okay, can maybe only be obtained in principle or requires a bit more tweaking, but you get what I mean). My experience with Stata is however that when Stata is making it difficult to do something, perhaps it shouldn't be done. Is that the case here? Is there something wrong with what I want that I don't see?
Thanks for your consideration
Gobinda
I would like to fit a random effects model with a categorical predictor variable and random coefficients for this categorical predictor variable--pretty much like the following:
Code:
webuse pig, clear // Get some example data set egen time = cut(week), group(4) label // Create a categorical variable
Code:
mixed weight i.time || id:
Code:
mixed weight i.time || id: i.time, cov(uns)
Code:
mixed weight i.time || id: r.time, cov(uns)
Code:
mixed weight i.time || id: r.time
My question now is: What does the r-operator do? Is it described anywhere in the documentation (sorry, I couldn't find it myself)?
As a bonus question:
I know that what I wanted to do initially -- a random coefficient model for a categorical predictor -- can be obtained when not using factor variables:
Code:
quietly tab time, gen(time) // Create set of dummies representing categorical variable mixed weight time2-time4 || id: time2-time4, cov(uns)
Thanks for your consideration
Gobinda