Hi,
How should I include categorical predictor variables in the random part of my model? Just entering “i.variable” gives the following message: i: operator invalid. Do I need to dumify the variables that I want to enter? Does this gives the same result as the procedure in MLwiN?
Thank you very much in advance,
Marjolijn
categorical predictors in the random part
-
- Posts: 4
- Joined: Tue Jan 28, 2014 9:42 pm
-
- Posts: 1384
- Joined: Mon Oct 19, 2009 10:34 am
Re: categorical predictors in the random part
Using the i.variable syntax in runmlwin will just create the dummies automatically under the covers, so using dummies that you create yourself should be equivalent. Alternatively if you prefix your command with: then the i.variable syntax should work in the random part too.
Code: Select all
xi:
-
- Site Admin
- Posts: 432
- Joined: Fri Apr 01, 2011 2:14 pm
Re: categorical predictors in the random part
Hi Marjolijn,
Here is an example of Chris' solution
Commands:
Output:
Here is an example of Chris' solution
Commands:
Code: Select all
* Load the data
use "http://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear
* Convert continuous standlrt into a 3-category oridnal variable called pass
generate pass = 2
replace pass = 1 if standlrt<-.75
replace pass = 3 if standlrt>.75
* Tabulate pass
tabulate pass
* Fit model with pass dummies and incorporate random slopes for the pass dummies
xi: runmlwin normexam cons standlrt i.pass, ///
level2(school: cons i.pass) ///
level1(student: cons) nopause
Code: Select all
. * Load the data
. use "http://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear
.
. * Convert continuous standlrt into a 3-category oridnal variable called pass
. generate pass = 2
.
. replace pass = 1 if standlrt<-.75
(876 real changes made)
.
. replace pass = 3 if standlrt>.75
(890 real changes made)
.
. * Tabulate pass
. tabulate pass
pass | Freq. Percent Cum.
------------+-----------------------------------
1 | 876 21.58 21.58
2 | 2,293 56.49 78.07
3 | 890 21.93 100.00
------------+-----------------------------------
Total | 4,059 100.00
.
. * Fit model with pass dummies and incorporate random slopes for the pass dummies
. xi: runmlwin normexam cons standlrt i.pass, ///
> level2(school: cons i.pass) ///
> level1(student: cons) nopause
i.pass _Ipass_1-3 (naturally coded; _Ipass_1 omitted)
MLwiN 2.29 multilevel model Number of obs = 4059
Normal response model
Estimation algorithm: IGLS
-----------------------------------------------------------
| No. of Observations per Group
Level Variable | Groups Minimum Average Maximum
----------------+------------------------------------------
school | 65 2 62.4 198
-----------------------------------------------------------
Run time (seconds) = 2.06
Number of iterations = 5
Log likelihood = -4658.0581
Deviance = 9316.1162
------------------------------------------------------------------------------
normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
cons | -.033233 .0564554 -0.59 0.556 -.1438836 .0774176
standlrt | .5294663 .0265595 19.94 0.000 .4774106 .581522
_Ipass_2 | .0079123 .0546539 0.14 0.885 -.0992075 .115032
_Ipass_3 | .0937119 .0903775 1.04 0.300 -.0834248 .2708485
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
Level 2: school |
var(cons) | .0734045 .0208721 .0324959 .1143131
cov(cons,_Ipass_2) | -.0126694 .0153444 -.0427439 .0174051
var(_Ipass_2) | .0439243 .0182607 .0081339 .0797146
cov(cons,_Ipass_3) | -.0110608 .0205914 -.0514193 .0292977
cov(_Ipass_2,_Ipass_3) | .0689854 .0232667 .0233835 .1145874
var(_Ipass_3) | .1117496 .0360596 .0410741 .1824251
-----------------------------+------------------------------------------------
Level 1: student |
var(cons) | .5538607 .0125606 .5292423 .5784791
------------------------------------------------------------------------------
-
- Posts: 4
- Joined: Tue Jan 28, 2014 9:42 pm
Re: categorical predictors in the random part
Thank your so much!
The "xi"-solution, however, gave me a new error-message saying "r(101) interaction not allowed". I searched the web and found that this means that a command (I supose the xi-command) isn't adjusted at the stata-version I use. Inculding 'version 10.1" didn't solve the problem. Sorry for bothering you with this new pure-stata-problem.
I also tried the syntax with dummified variables and this did worked. So thank you!
Best regards,
Marjolijn
The "xi"-solution, however, gave me a new error-message saying "r(101) interaction not allowed". I searched the web and found that this means that a command (I supose the xi-command) isn't adjusted at the stata-version I use. Inculding 'version 10.1" didn't solve the problem. Sorry for bothering you with this new pure-stata-problem.
I also tried the syntax with dummified variables and this did worked. So thank you!
Best regards,
Marjolijn
-
- Site Admin
- Posts: 432
- Joined: Fri Apr 01, 2011 2:14 pm
Re: categorical predictors in the random part
Hi Marjolijn,
Note that if you specify interactions then you will need to do more than just add the xi prefix when moving from Stata's current notation to their historic notation
See help xi for examples of how to specify interactions
If runmlwin still throws up an error then please post the do-file and dataset to replicate that error.
Best wishes
George
Note that if you specify interactions then you will need to do more than just add the xi prefix when moving from Stata's current notation to their historic notation
See help xi for examples of how to specify interactions
If runmlwin still throws up an error then please post the do-file and dataset to replicate that error.
Best wishes
George
-
- Posts: 4
- Joined: Tue Jan 28, 2014 9:42 pm
Re: categorical predictors in the random part
Thank you very much!!
Marjolijn
Marjolijn