Issues running 2-level nominal response model

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
LizzieSimon
Posts: 5
Joined: Fri Jul 03, 2020 10:25 am

Issues running 2-level nominal response model

Post by LizzieSimon »

Hi,

I am currently trying to use runmlwin to estimate a 2-level nominal response model (on multiply imputed data, 10 imputations, mlong format) in Stata but am running into problems. The model dependent variable is comprised of three, un-ordered categories - voting Labour, voting Conservative or voting for another party. Pano is the variable which indicates clustering and idnew has been created to indicate the ordering of observations within each of these clusters.

The syntax I am currently running is:
gen cons = 1
bysort pano: gen idnew = _n
sort pano idnew
label define gevote20171 1 "Conservative" 2 "Labour" 3 "Other"
label values gevote2017 gevote20171
. global MLwiN_path C:\Program Files\MLwiN v3.04\mlwin.exe
xi: mi estimate, cmdok noisily: runmlwin gevote2017 cons i.ed3cat gender ethnicity parentclass i.polinterest i.age country i.socialclass i.hhincome i.ordinarypeople i.immigrationecon immigrantnumber i.justice i.tradvalues i.nationalid i.news i.populism i.likemay i.likecorbyn i.likefarron i.likelucas i.keyissue, level2(pano: cons) level1(idnew: ) discrete(distribution(multinomial) link(mlogit) denominator(cons) basecategory(1)) nopause

This leads to the following error message being reported:
'The data must be sorted according to the order of the model hierarchy: pano idnew idnew. An error occurred when mi estimate executed runmlwin on m=1'.

When I go into the data viewer to check the structure of my data it appears to be structured appropriately by pano and then idnew, within pano. I'm not sure why the error message is suggesting three layers of sorting are needed, but suspect this may be related to the way I have specified the cons variable.

Apologies if I have not provided some important information - I am new to the forum so not sure exactly what is needed.

Any help in working out why I am running into this error/getting this model to run would be much appreciated.

Best wishes,

Lizzie

ChrisCharlton
Posts: 1182
Joined: Mon Oct 19, 2009 10:34 am

Re: Issues running 2-level nominal response model

Post by ChrisCharlton »

I think that the error is caused by the way you have generated the idnew variable, where it restarts numbering within each higher-level unit. Normally this doesn't matter as MLwiN doesn't actually use the lowest level ID variables for anything, however in multinomial models the data is expanded and everything is pushed up a level with this becoming the level-2 indicator signifying the response.

If you want to keep the data as-is you can specify the nosort option (see the runmlwin help file), which prevents the check to see whether the data is sorted correctly. Alternatively you can replace the lines:

Code: Select all

bysort pano: gen idnew = _n
sort pano idnew
with

Code: Select all

sort pano
gen idnew = _n
which should create the ID variable in the way expected by runmlwin.

LizzieSimon
Posts: 5
Joined: Fri Jul 03, 2020 10:25 am

Re: Issues running 2-level nominal response model

Post by LizzieSimon »

Hi Chris,

Thanks for your prompt reply and for your suggestions.

I have tried switching out the lines of code and Stata is still returning the 'The data must be sorted according to the order of the model hierarchy: pano idnew idnew. An error occurred when mi estimate executed runmlwin on m=1'. error.

When I keep the data as-is and use the no sort option I get an error in MLwiN which reads as 'error while obeying batch file: unexpanded level 2 id column(idnew) must not contain consecutive repeated codes, in multivariate models. Use generate to create the expected id variable'.

I have also tried adding the no sort option after replacing the lines of code. This leads the following error to be reported in Stata: 'The model did not run properly in MLwiN. You most likely clicked the 'Abort Macro' button in MLwiN, rather than the 'Resume Macro' button.' I am definitely not pressing the abort button, I have re-run a couple of times to check, so it seems that running the model is causing some kind of crash.

Please let me know if you have any further suggestions as to how I might get this model to run.

Lizzie

ChrisCharlton
Posts: 1182
Joined: Mon Oct 19, 2009 10:34 am

Re: Issues running 2-level nominal response model

Post by ChrisCharlton »

Could you try removing the nopause option from your command and then checking the ID structure within MLwiN when it opens? You can look at the data via the Data Manipulation->View or edit data menu. You can see what MLwiN believes the data structure to be either by looking at Model->Hierarchy Viewer or Model->Equations.

LizzieSimon
Posts: 5
Joined: Fri Jul 03, 2020 10:25 am

Re: Issues running 2-level nominal response model

Post by LizzieSimon »

Thanks again for your help Chris!

I have now re-run the commands without the nopause option and have swapped out the 2 lines of code for those you suggested. When I go into MLwiN to look at the hierarchy viewer it appears as follows:
Model Hierarchy.png
Model Hierarchy.png (3.91 KiB) Viewed 336 times
As far as I can tell, the sorting has been carried out as it should have been, with the response being specified as level 1, respondents (idnew) being specified as level 2 and the constituency (pano) being specified as level 3. Is this correct? As before, once I hit resume macro in MLwiN Stata returns the following error 'The model did not run properly in MLwiN. You most likely clicked the 'Abort Macro' button in MLwiN, rather than the 'Resume Macro' button.' Can you let me know what I might be able to do to get this model to run?

Best wishes,

Lizzie

ChrisCharlton
Posts: 1182
Joined: Mon Oct 19, 2009 10:34 am

Re: Issues running 2-level nominal response model

Post by ChrisCharlton »

A couple of things you could try are:
  1. When MLwiN opens click Abort Macro, then try running the model within MLwiN via the Start button to see if it works or you get any more informative error messages.
  2. Try changing the base category for the model, as this can sometimes make a difference to whether the model fits in MLwiN.

LizzieSimon
Posts: 5
Joined: Fri Jul 03, 2020 10:25 am

Re: Issues running 2-level nominal response model

Post by LizzieSimon »

Thank you for all your help so far Chris!

When aborting the macro and running the model in MLwiN via start I get the following error message: ‘SSP matrix for the random part has gone negative definitive - a reconstruction to the nearest non-negative form has been used.’

When I run the model using base category 2 rather than base category 1 as the reference I get the following error in Stata 'IGLS algorithm failed to converge. Increase the number of iterations. Model did not converge on m=1'. If i then increase the number of iterations to 100, using the maxiterations(100) option, this model which uses base category 2 as the reference now runs fine. Is the fact that such a large number of iterations are needed to achieve convergence problematic?

ChrisCharlton
Posts: 1182
Joined: Mon Oct 19, 2009 10:34 am

Re: Issues running 2-level nominal response model

Post by ChrisCharlton »

Although you specified a maximum of 100 iterations it may be doing a lot fewer, you would need to check the model output to see whether this is the case. I don't think that taking more than the default maximum number of iterations is necessarily problematic, although you should probably think about whether the results look plausible. If you run the model directly in MLwiN you can see the estimates changing at each iteration, which would give an idea of whether it is struggling with a few parameters or if they are changing a lot at each iteration. You could also compare the results to those given by other packages if you have them available.

LizzieSimon
Posts: 5
Joined: Fri Jul 03, 2020 10:25 am

Re: Issues running 2-level nominal response model

Post by LizzieSimon »

Okay great, I will look into this further. Thanks very much for all your help Chris!

Post Reply