Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 65123

Understanding the r-operator for -mixed- models

$
0
0
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:

Code:
webuse pig, clear // Get some example data set
egen time = cut(week), group(4) label // Create a categorical variable
The model I want to fit looks like this:

Code:
mixed weight i.time || id:
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:

Code:
mixed weight i.time || id: i.time, cov(uns)
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:

Code:
mixed weight i.time || id: r.time, cov(uns)
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:

Code:
mixed weight i.time || id: r.time
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:

Code:
quietly tab time, gen(time)  // Create set of dummies representing categorical variable
mixed weight time2-time4 || id: time2-time4, cov(uns)
(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

Viewing all articles
Browse latest Browse all 65123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>