Categorical variable as a predictor

Welcome to the forum for runmlwin users. Feel free to post your question about runmlwin here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Go to runmlwin: Running MLwiN from within Stata >> http://www.bristol.ac.uk/cmm/software/runmlwin/
Post Reply
UmmAymanBarakah
Posts: 7
Joined: Sat Apr 05, 2025 9:06 pm

Categorical variable as a predictor

Post by UmmAymanBarakah »

Please take the table below as an example: industry is a predictor variable that the firm belongs to. In looking at the example codes the mlwin manual provides, it looks likes predictor variables entered differently. e.g. runmlwin use4 cons (age lc1 lc2 lc3plus urban, contrast(1/3)), ///
> level2(district: (cons, contrast(1/3))) ///
> level1(woman:) ///
> discrete(dist(multinomial) link(ologit) denom(cons) basecategory(4)) ///
> mcmc(orthogonal) initsprevious ///
> nopause nogroup

My question is that do I make my data (the inductry part in wide form so that I can include it in my code like the example code above for lc1, lc2, lc3plus.
ID perf signals industry
A 1964 60 311
B 145 0 322
C 4445 55 311
D 97000 101 333
E 850 98 333
F 201 19 313
G 149 11 313
H 90177 120 322
ChrisCharlton
Posts: 1384
Joined: Mon Oct 19, 2009 10:34 am

Re: Categorical variable as a predictor

Post by ChrisCharlton »

lc1 lc2 and lc3plus are dummy variables that were created from the categorical variable lc. You can see the code that was used to create them at the beginning of the replication example for chapter 10 of the MLwiN user's guide (https://www.bristol.ac.uk/cmm/media/run ... sponses.do). As an alternative you can use the xi Stata prefix (https://www.stata.com/help.cgi?xi), which will generate the dummies for you. The factor-variable notation (https://www.stata.com/links/stata-basic ... -notation/) should also work for predictors in the fixed part.
UmmAymanBarakah
Posts: 7
Joined: Sat Apr 05, 2025 9:06 pm

Re: Categorical variable as a predictor

Post by UmmAymanBarakah »

Thanks for the response. I am aware lc1, lc2....are dummy variables. Industry can be coded as dummy variables since it is a categorial data. My question is: if I have a categorical data such as the industry example, do I have to generate a dummy variable like the one in this code example?
Is this the only way or can I just include as a categorical data just like stata?
ChrisCharlton
Posts: 1384
Joined: Mon Oct 19, 2009 10:34 am

Re: Categorical variable as a predictor

Post by ChrisCharlton »

runmlwin should (more or less) work like any other Stata command, so you should be able to use the standard Stata facilities to create the required dummies. I think that the example we provide only does it manually to make the process more explicit (and give the generated dummies names of our choosing). It is however often a good idea to call runmlwin without the nopause option so that you can examine the data/model within MLwiN to check that it matches your expectations.
hedstyle
Posts: 2
Joined: Wed Apr 16, 2025 6:54 am

Re: Categorical variable as a predictor

Post by hedstyle »

Thanks for the clarification! Just to double-check: if I create my dummies using tab varname, gen(dummy), runmlwin should handle them just fine, right?
Post Reply