Hi, all,
I try to use the mixed command to run some mixed effect model. Here is an example to show what I am doing:
In this model, rep78 and foreign are two non-clustered random intercepts. My questions is, is it possible to specify the mpg as a random slope within the foreign level? What I want is something like:
I can't use the above code since stata will automatically assume foreign is clustered within rep78, but actually those two variables are not clustered. The estimation is not correct. That's why I am using _all:R.varname to claim those 2 non-clustered random intercepts. But I don't know how to add a random slope in my first model. I read through the help documents, but didn't see any information about this. Any suggestions and ideas are greatly appreciated!
BTW:
I am also a R user, if you are familiar with R and lme4 package. What I want is something like (in R):
Thank you in advance!
I try to use the mixed command to run some mixed effect model. Here is an example to show what I am doing:
Code:
. sysuse auto2.dta (1978 Automobile Data) . mixed price mpg ||_all:rep78 || _all:foreign Performing EM optimization: Performing gradient-based optimization: Iteration 0: log likelihood = -639.24539 Iteration 1: log likelihood = -639.18966 Iteration 2: log likelihood = -639.17544 Iteration 3: log likelihood = -639.17536 Iteration 4: log likelihood = -639.17536 Computing standard errors: Mixed-effects ML regression Number of obs = 69 Group variable: _all Number of groups = 1 Obs per group: min = 69 avg = 69.0 max = 69 Wald chi2(1) = 21.84 Log likelihood = -639.17536 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ price | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- mpg | -265.2104 56.75339 -4.67 0.000 -376.445 -153.9758 _cons | 11462.59 1185.269 9.67 0.000 9139.502 13785.67 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ _all: Identity | var(rep78) | 7.58e-09 .0000215 0 . -----------------------------+------------------------------------------------ _all: Independent | var(foreign) | 1423223 2870677 27313.56 7.42e+07 var(_cons) | 1.13e-08 4.73e-07 3.63e-44 3.55e+27 -----------------------------+------------------------------------------------ var(Residual) | 6348319 1092162 4531254 8894041 ------------------------------------------------------------------------------ LR test vs. linear regression: chi2(3) = 1.17 Prob > chi2 = 0.7612 Note: LR test is conservative and provided only for reference.
Code:
. mixed price mpg ||rep78:mpg || foreign:
BTW:
I am also a R user, if you are familiar with R and lme4 package. What I want is something like (in R):
Code:
lmer(price ~ mpg + (1|rep78) + (1+ mpg|foreign), auto2, REML = F)
Comment