How to replicate Stata do-file of MLRA using "runmlwin", please advise

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/
hamzah734
Posts: 8
Joined: Sat Jan 06, 2018 7:48 pm

How to replicate Stata do-file of MLRA using "runmlwin", please advise

Post by hamzah734 »

Hello everyone,


I am a new user of MLwiN and multilevel modelling too. I am writing an article both 2-level model and the 3-level model, which inspired by a great paper: An Original Stepwise Multilevel Logistic Regression Analysis (MLRA) of Discriminatory Accuracy: The Case of Neighbourhoods and Health

https://journals.plos.org/plosone/artic ... ne.0153778 . The dependent variable is dichotomous (0=not disease, 1=disease) which use the multivariable logistic regression for a binary response and the independent variables also in dichotomous (0=yes 1=not)
Would you please translate my variable below in order can be running into MLwiN. I see "runmlwin" should be quicker for MLRA on big datasets especially with three level models or if I want to put in random slope. Isn’t it?

Further, I have read the 9th of MLwiN User and the 10th of MLwiN MCMC Manual
9. Logistic Models for Binary and Binomial Responses (do | log)
10. Modelling Binary Responses (do | log)
However, I am a little bit confused to replicate into my hierarchical data, below

Districts (3rd level) _k : human development index (HDI)
Households (2nd level) _kj : knowledge of household
Individuals (1st level)_kji : gender, i.age, job
Outcome of this research : malaria prevalence

Would you please help me, to replicate do-file below in order can be run with “runmlwin” in ordering the analysis process that will be run by "Stata 14" and "MLwiN" trial version at the moment.

The 2-level model
MODEL 1 - Simple logistic regression analysis = SCAE
logit malaria gender i.age job
MODEL 2 - Multilevel logistic regression = SCAE + GCE
melogit malaria gender i.age job || district :
MODEL 3 - MLRA with neighbourhood = SCAE + GCE + SCE
melogit malaria gender i.age job HDI || district :
Multilevel logistic regression (MLRA) for malaria prevalence in two-level analysis.


I was translated the do-file into the Multilevel logistic regression (MLRA) for malaria prevalence in the two-level analysis. Using the trial version of MLwiN which have changed the location of the MLwiN_path global to the appropriate place, i.e. something like:global MLwiN_path "C:\Program Files (x86)\MLwiN trial\i386\mlwin.exe" and I have to click the "continue trial" button for each of my models are MLwiN is re-opened each time a new model is run. However, I am not sure if the syntax for MLwiN is true already; please suggest.

The data structure is hierarchical in the 2-level model with
Districts: ID District (2nd level)_j
Individuals: gender i.age job (1st level)_ij


* generate constant
gen cons = 1
* generate level-1 ID variable
gen id = _n


* run with IGLS
runmlwin malaria cons gender i.age job, level2(district: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) nopause

* run MCMC using IGLS values as starting values
runmlwin malaria cons gender i.age job, level2(district: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(on) initsprevious nopause


My questions are:

How to generate Simple logistic regression model, and denominator?

How to replicate S1 Stata. Stata do-file for running all the models, into to “runmlwin” if we want to measure the six (6) criteria, based on hierarchical data that we have

1. Interclass correlation (ICC),
2. Median odds-ratio (MOR),
3. 80% interval odds-ratio (IOR),
4. The proportion of opposed odds-ratios (POOR)
5. Proportion change in variance (PCV), and
6. Receiver operating characteristic (ROC): AU-ROC and AU-ROC change


Besides, I should perform the estimations using MCMC (this is an advice for all the analysis) that MCMC is available if I have MLwiN and can be run within stata as runmlwin command. Isn't it?

And how to replicate the three-level analysis below
Districts (3rd level) _k : human development index (HDI)
Households (2nd level) _kj : knowledge of household
Individuals (1st level)_kji : gender, i.age, job

Finally, if I have another data set, how to work and save like data below

S1 Model. MLwiN worksheet for running the equation of model 1 concerning utilization of a private versus public general practitioner.
https://doi.org/10.1371/journal.pone.0153778.s005
(WSZ)
S2 Model. MLwiN worksheet for running the equation of model 2 concerning utilization of a private versus public general practitioner.
https://doi.org/10.1371/journal.pone.0153778.s006
(WSZ)
S3 Model. MLwiN worksheet for running the equation of model 3 concerning utilization of a private versus public general practitioner.
https://doi.org/10.1371/journal.pone.0153778.s007
(WSZ)
S4 Model. MLwiN worksheet for running the equation of model 1 concerning utilization of psychotropic medication.
https://doi.org/10.1371/journal.pone.0153778.s008
(WSZ)
S5 Model. MLwiN worksheet for running the equation of model 2 concerning utilization of psychotropic medication.
https://doi.org/10.1371/journal.pone.0153778.s009
(WSZ)
S6 Model. MLwiN worksheet for running the equation of model 3 concerning utilization of psychotropic medication.
https://doi.org/10.1371/journal.pone.0153778.s010
(WSZ)


I am so sorry if my discussion is too long because I am beginner implementing "runmlwin" to Multilevel Logistic Regression Analysis.


Kind regards,
ChrisCharlton
Posts: 1348
Joined: Mon Oct 19, 2009 10:34 am

Re: How to replicate Stata do-file of MLRA using "runmlwin", please advise

Post by ChrisCharlton »

The code that you quoted looks correct for a simple logistic regression model.

If your response is zero/one (i.e. not proportions) then the denominator that you create will just be a column of ones. You can create this in the same way as you generated the cons variable (or just use the cons variable itself as you have done in your example). If you do have proportions then see the last couple of models at the end of chapter 9 of the MLwiN user guide (along with the Stata syntax available at http://www.bristol.ac.uk/cmm/software/r ... /examples/).

If you wanted to replicate the models that you link to at the end of your post then the code would look something like:

Code: Select all

* generate constant
gen cons = 1
* generate level-1 ID variable
gen id = _n
* generate denominator
gen denom = 1

* Model s005
* run with RIGLS to create starting values
runmlwin private cons i.agegroup male rich, level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) rigls nopause
* run MCMC using the above
runmlwin private cons i.agegroup male rich, level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(seed(13) burnin(5000) chain(10000)) initsprevious nopause

* Model s006
* run with RIGLS to create starting values
runmlwin private cons i.agegroup male rich, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) rigls nopause
* run MCMC using the above
runmlwin private cons i.agegroup male rich, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(seed(13) burnin(5000) chain(10000)) initsprevious nopause

* Model s007
* run with RIGLS to create starting values
runmlwin private cons i.agegroup male rich richarea, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) rigls nopause
* run MCMC using the above
runmlwin private cons i.agegroup male rich richarea, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(seed(13) burnin(5000) chain(10000)) initsprevious nopause

* Model s008
* run with RIGLS to create starting values
runmlwin psycmed cons i.agegroup male poor, level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) rigls nopause
* run MCMC using the above
runmlwin psycmed cons i.agegroup male poor, level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(seed(13) burnin(5000) chain(10000)) initsprevious nopause

* Model s009
* run with RIGLS to create starting values
runmlwin psycmed cons i.agegroup male poor, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) rigls nopause
* run MCMC using the above
runmlwin psycmed cons i.agegroup male poor, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(seed(13) burnin(5000) chain(10000)) initsprevious nopause

* Model s010
* run with RIGLS to create starting values
runmlwin psycmed cons i.agegroup male poor poorarea, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) rigls nopause
* run MCMC using the above
runmlwin psycmed cons i.agegroup male poor poorarea, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(seed(13) burnin(5000) chain(10000)) initsprevious nopause
To save an MLwiN worksheet (.wsz) for the model you just need to add the saveworksheet() option with an appropriate file name to the end of your -runmlwin- command. See:

Code: Select all

help runmlwin
for more details.
hamzah734
Posts: 8
Joined: Sat Jan 06, 2018 7:48 pm

Re: How to replicate Stata do-file of MLRA using "runmlwin", please advise

Post by hamzah734 »

Dear Chris,

Thank you very much for your great feedback.

Based on your direction, I have read how to save Stata dataset as MLwiN worksheet (savewsz)
at http://fmwww.bc.edu/RePEc/bocode/s/savewsz.html

Besides, I have created Stata do-file to replicate all analyses using runmlwin which I obtained from https://journals.plos.org/plosone/artic ... ne.0153778, before I analysis my data-sets, kindly see below.

Code: Select all

****************************************************************************
* RUNMLWIN - A PROGRAM TO RUN THE MLWIN MULTILEVEL MODELLING SOFTWARE FROM
*            WITHIN STATA
*    	     Stata do-file to replicate all analyses using runmlwin
*            George Leckie and Chris Charlton
*            Centre for Multilevel Modelling
*            University of Bristol
*
*            http://www.bristol.ac.uk/cmm/software/runmlwin/
*
********************************************************************************
* MERLO 2015
********************************************************************************
*TABLE 1
********************************************************************************
log using "$runmlwin journal.pone.0153778.s004.smcl", replace

* Load the data
use "runmlwin journal.pone.0153778.s004.dta", clear

* Number of individuals and number of neighborhoods
codebook neigh, compact

* Number of poor neighborhoods and number of individuals in those neighborhoods
codebook neigh if poorarea==1, compact


* Number of rich neighborhoods and number of individuals in those neighborhoods
codebook neigh if richarea==1, compact

* Descriptive statistics by neighborhood type
tabulate agegroup, missing generate(agegr)
by richarea, sort: tabstat psycmed private poor male agegr?, columns(statistics) format(%9.2f)

****************************************************************************
* The runmlwin command
****************************************************************************

* Install the runmlwin command from the Statistical Software Components
* (SSC) archive

ssc install runmlwin

* Specify the file address for mlwin.exe on the computer as the global macro MLwiN_path
* global MLwiN_path "C:\Program Files\MLwiN v2.26\i386\mlwin.exe"

global MLwiN_path "C:\Program Files (x86)\MLwiN trial\i386\mlwin.exe

********************************************************************************
* TABLE 2 - PSYCHOTROPIC DRUG USE
********************************************************************************
* Load the data
use "runmlwin journal.pone.0153778.s004.dta", clear

generate constant
gen cons = 1
* generate level-1 ID variable
gen id = _n
* generate denominator
gen denom = 1

* Model s008 (to replicate MODEL 1 - Simple logistic regression analysis with fit model (logit psycmed male i.agegroup poor))
* run with RIGLS to create starting values
runmlwin psycmed cons i.agegroup male poor, level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) rigls nopause

* run MCMC using the above
runmlwin psycmed cons i.agegroup male poor, level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(seed(13) burnin(5000) chain(10000)) initsprevious nopause
savewsz Model s008, replace


* Model s009 (to replicate MODEL 2 - Multilevel logistic regression with fit model (melogit psycmed male i.agegroup poor || neigh:))
* run with RIGLS to create starting values
runmlwin psycmed cons i.agegroup male poor, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) rigls nopause

* run MCMC using the above
runmlwin psycmed cons i.agegroup male poor, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(seed(13) burnin(5000) chain(10000)) initsprevious nopause
savewsz Model s009, replace


* Model s010 (to replicate MODEL 3 - Multilevel logistic regression with neighborhood income with fit model (melogit psycmed male i.agegroup poor poorarea || neigh:))
* run with RIGLS to create starting values
runmlwin psycmed cons i.agegroup male poor poorarea, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) rigls nopause


* run MCMC using the above
runmlwin psycmed cons i.agegroup male poor poorarea, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(seed(13) burnin(5000) chain(10000)) initsprevious nopause
savewsz Model s010, replace

********************************************************************************
translate "$smcl\runmlwin journal.pone.0153778.s004.smcl" ///
"$log\runmlwin journal.pone.0153778.s004.log", replace

savewsz, replace

** Congratulation **

log close 

Authors

    George Leckie
    Centre for Multilevel Modelling
    University of Bristol
    g.leckie@bristol.ac.uk


    Chris Charlton
    Centre for Multilevel Modelling
    University of Bristol


Acknowledgements

    We are very grateful to colleagues at the Centre for Multilevel Modelling and the University of Bristol for their useful comments.
    The development of this command was funded under the LEMMA project, a node of the UK Economic and Social Research Council's National Centre for Research Methods (grant number RES-576-25-0003).
	
References

    Browne, W.J. 2012. MCMC Estimation in MLwiN, v2.26.  Centre for Multilevel Modelling, University of Bristol.
        http://www.bristol.ac.uk/cmm/software/mlwin/download/manuals.html

    Leckie, G. and Charlton, C. 2013. runmlwin - A Program to Run the MLwiN Multilevel Modelling Software from within Stata. Journal of Statistical Software, 52 (11),1-40.
        http://www.jstatsoft.org/v52/i11

    Rabe-Hesketh, S. and Skrondal, A. 2012. Multilevel and Longitudinal Modeling using Stata (Third Edition). College Station, TX: Stata Press.

    Rasbash, J., Steele, F., Browne, W.J. and Goldstein, H. 2012. A Users Guide to MLwiN, v2.26. Centre for Multilevel Modelling, University of Bristol.
        http://www.bristol.ac.uk/cmm/software/mlwin/download/manuals.html
However when I executed the *.do.file, in this stage.

Code: Select all

. * Model s008
. * run with RIGLS to create starting values
. runmlwin psycmed cons i.agegroup male poor, level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) rigls nopause
 
I face a problem below,

note: 1b.agegroup omitted because of collinearity,

Image

Image

The process is stuck at the moment, please advise.


Best
Attachments
Figure 2
Figure 2
2.JPG (21.14 KiB) Viewed 16741 times
Figure 1
Figure 1
1.JPG (12.97 KiB) Viewed 16741 times
Last edited by hamzah734 on Thu Feb 28, 2019 10:40 am, edited 1 time in total.
ChrisCharlton
Posts: 1348
Joined: Mon Oct 19, 2009 10:34 am

Re: How to replicate Stata do-file of MLRA using "runmlwin", please advise

Post by ChrisCharlton »

Although the provided savewsz creates an MLwiN worksheet this will only contain the current Stata data file, not the model specified. To get the model as well you need to instead use the saveworksheet option of the -runmlwin- command, i.e.:

Code: Select all

runmlwin psycmed cons i.agegroup male poor, level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(seed(13) burnin(5000) chain(10000)) initsprevious nopause saveworksheet(Models008, replace)
The message that you are seeing may be due to a memory allocation setting in older versions of MLwiN (including the trial version). Could you try adding the mlwinsettings(optimat) to the end of your -runmlwin- command and seeing whether that fixes it?
hamzah734
Posts: 8
Joined: Sat Jan 06, 2018 7:48 pm

Re: How to replicate Stata do-file of MLRA using "runmlwin", please advise

Post by hamzah734 »

Thank you very much, i just saw mlwinsettings(optimat) at https://www.bristol.ac.uk/cmm/media/runmlwin/3.3.do
and I have a little bit change the *.do file below

Code: Select all

. * Model s008
. * run with RIGLS to create starting values
. runmlwin psycmed cons i.agegroup male poor, level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) rigls mlwinsettings(optim
> at) nopause 
 
note: 1b.agegroup omitted because of collinearity
MLwiN 2.36 multilevel model                     Number of obs      =     43291
Binomial logit response model
Estimation algorithm: RIGLS, MQL1

Run time (seconds)   =       6.66
Number of iterations =          5
------------------------------------------------------------------------------
     psycmed |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        cons |  -1.538653   .0327579   -46.97   0.000    -1.602857   -1.474449
 _2_agegroup |   .2980971   .0401941     7.42   0.000      .219318    .3768761
 _3_agegroup |   .4897574   .0403411    12.14   0.000     .4106903    .5688246
 _4_agegroup |   .5929487   .0397541    14.92   0.000      .515032    .6708653
 _5_agegroup |   .6462153   .0392743    16.45   0.000      .569239    .7231916
 _6_agegroup |   .6686541    .039716    16.84   0.000     .5908122    .7464961
        male |  -.4948737   .0229556   -21.56   0.000    -.5398659   -.4498815
        poor |   .5111752   .0223171    22.91   0.000     .4674346    .5549159
------------------------------------------------------------------------------

r; t=6.68 17:50:22

. * run MCMC using the above
. runmlwin psycmed cons i.agegroup male poor, level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(seed(13) burnin(5000
> ) chain(10000)) initsprevious mlwinsettings(optimat) nopause saveworksheet(Models008, replace)
 
note: 1b.agegroup omitted because of collinearity
MLwiN 2.36 multilevel model                     Number of obs      =     43291
Binomial logit response model
Estimation algorithm: MCMC

Burnin                     =       5000
Chain                      =      10000
Thinning                   =          1
Run time (seconds)         =        500
Deviance (dbar)            =   48197.52
Deviance (thetabar)        =   48189.50
Effective no. of pars (pd) =       8.01
Bayesian DIC               =   48205.52
------------------------------------------------------------------------------
     psycmed |      Mean    Std. Dev.     ESS     P       [95% Cred. Interval]
-------------+----------------------------------------------------------------
        cons |  -1.540481   .0329259      169   0.000    -1.611206   -1.479318
 _2_agegroup |   .3002465   .0401345      293   0.000      .222513    .3802997
 _3_agegroup |   .4912666   .0405349      299   0.000     .4137993    .5702286
 _4_agegroup |   .5949197   .0389349      308   0.000     .5213393    .6740683
 _5_agegroup |   .6493196   .0387069      336   0.000     .5758997    .7289256
 _6_agegroup |   .6710117   .0396138      315   0.000      .594569    .7504479
        male |  -.4956414   .0231762     1300   0.000    -.5422289   -.4520892
        poor |   .5113981   .0216416      935   0.000     .4680969      .55297
------------------------------------------------------------------------------
The process is running and I will continue to the next stage


Best
hamzah734
Posts: 8
Joined: Sat Jan 06, 2018 7:48 pm

Re: How to replicate Stata do-file of MLRA using "runmlwin", please advise

Post by hamzah734 »

Dear Chris,

In the next stage

Code: Select all


. * Model s009
. * run with RIGLS to create starting values
. runmlwin psycmed cons i.agegroup male poor, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) rigls mlwinsettings(optimat) nopause 
the problem which I face are:

note: 1b.agegroup omitted because of collinearity
The data must be sorted according to the order of the model hierarchy: neigh id.

and in addition

Code: Select all

. * run MCMC using the above
. runmlwin psycmed cons i.agegroup male poor, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(
> seed(13) burnin(5000) chain(10000)) initsprevious mlwinsettings(optimat) nopause saveworksheet(Models009, replace)

note: 1b.agegroup omitted because of collinearity
The data must be sorted according to the order of the model hierarchy: neigh id.

as well as in the code

Code: Select all

* Model s010
* run with RIGLS to create starting values
runmlwin psycmed cons i.agegroup male poor poorarea, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) rigls mlwinsettings(optimat) nopause 
* run MCMC using the above
runmlwin psycmed cons i.agegroup male poor poorarea, level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) mcmc(seed(13) burnin(5000) chain(10000)) initsprevious mlwinsettings(optimat) nopause saveworksheet(Models010, replace)

note: 1b.agegroup omitted because of collinearity
The data must be sorted according to the order of the model hierarchy: neigh id.


Do you have any suggestions?

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

Re: How to replicate Stata do-file of MLRA using "runmlwin", please advise

Post by ChrisCharlton »

Unless you are fitting your data as cross-classified MLwiN determines the higher levels by a change in the identifier, rather than the identifier itself. This means that if you had data such as the following it would consider there to be three units instead of two:

Code: Select all

student_id school_id
1          1
2          1
3          1
4          2
5          2
6          2
7          1
8          1
9          1
You therefore need to ensure that your data is sorted by the model hierarchy before running the model. You can either do this yourself before fitting the model, which allows you to check that it is sorted as you expect or you can use the forcesort option in -runmlwin-. If you believe that the data is sorted the way that you want it and want to disable the check in -runmlwin- you can use the nosort option. For more details see:

Code: Select all

help runmlwin
within Stata.
hamzah734
Posts: 8
Joined: Sat Jan 06, 2018 7:48 pm

Re: How to replicate Stata do-file of MLRA using "runmlwin", please advise

Post by hamzah734 »

Dear Chris,

Thank you for your knowledge. I just read forcesort.
Other - (R)IGLS and MCMC
forcesort. forces the data to be sorted according to the model hierarchy
forcesort forces the data sent to MLwiN to be sorted according to the model hierarchy. We recommend that users sort their data manually using the sort command before using.

After sort their data using the sort command.

Syntax

Code: Select all

sort varlist [in] [,stable]
and the next process succeed executed

However, when I make command would look something like:

Code: Select all

 * run MCMC using the above
 runmlwin psycmed cons male iagegroup poor, ///
                 level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) ///
                 mcmc(seed(13) burnin(5000) chain(10000)) initsprevious mlwinsettings(optimat) nopause ///
                 saveworksheet(S2-Model, replace)
 
sometimes I have a problem
note: 1b.agegroup omitted because of collinearity
unable to restore data due to insufficient memory; try to discard first
could not restore sort order because variables were dropped
r(601); t=591.71 7:05:43
end of do-file
r(601); t=617.80 7:05:43
In another hand, sometimes I have found a matter.

note: 1b.agegroup omitted because of collinearity
file C:\Users\My PC\AppData\Local\Temp\ST_00000008.tmp cannot be modified or erased; likely cause is read-only directory or file
r(608); t=0.81 7:03:54
end of do-file
r(608); t=24.95 7:03:54
Do you have any idea for solving the problem when the notification of above will come?

In addition, should I make command below, when I will execute each of the *.do file?

Code: Select all

* Install the runmlwin command from the Statistical Software Components
* (SSC) archive

ssc install runmlwin, replace

* Specify the file address for mlwin.exe on the computer as the global macro MLwiN_path
* global MLwiN_path "C:\Program Files\MLwiN v2.26\i386\mlwin.exe"

global MLwiN_path "C:\Program Files (x86)\MLwiN trial\i386\mlwin.exe"
or enough I make once the command and for another or next the *.do file, for a trial version I only make

Code: Select all

* Specify the file address for mlwin.exe on the computer as the global macro MLwiN_path
* global MLwiN_path "C:\Program Files\MLwiN v2.26\i386\mlwin.exe"
global MLwiN_path "C:\Program Files (x86)\MLwiN trial\i386\mlwin.exe"
without I make again the command below

Code: Select all

 ssc install runmlwin, replace 
Finally, may I know are the commands, with replicate Stata do-file of MLRA using "runmlwin", can measure all parameters of the linked journal?
or may the commands combined use the syntax from the *.do file of the journal as would like

Code: Select all

* Model s008
* run with RIGLS to create starting values
runmlwin psycmed cons male i.agegroup poor, ///
        level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) ///
        rigls mlwinsettings(optimat) nopause ///
        saveworksheet(S1-Model, replace)
        
* run MCMC using the above
runmlwin psycmed cons male i.agegroup poor, ///
        level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) ///
        mcmc(seed(13) burnin(5000) chain(10000)) initsprevious mlwinsettings(optimat) nopause ///
        saveworksheet(S2-Model, replace)
        
        * Fit model
        logit psycmed male i.agegroup poor
        * Odds-ratios
        estimates store r1m1
        logit, or cformat(%9.2f)


........
and so on to measures all parameters of the journal linked.
Please advise.

I’m grateful for the update, and I look forward to hearing back from you about the next stage of the process.

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

Re: How to replicate Stata do-file of MLRA using "runmlwin", please advise

Post by ChrisCharlton »

You get the message:

Code: Select all

note: 1b.agegroup omitted because of collinearity
because you are entering the variable agegroup as a factor (see https://www.stata.com/features/overview ... variables/) but not specifying a base category. Stata therefore attempts to create dummies for all factor levels, one of which gets dropped later. If you wanted to have more control over this you could explicitly set the base category by changing it to something like:

Code: Select all

ib(first).agegroup
The error message:

Code: Select all

file C:\Users\My PC\AppData\Local\Temp\ST_00000008.tmp cannot be modified or erased; likely cause is read-only directory or file
would normally occur because one of the temporary files that Stata is using to pass information to MLwiN is still open. This can either be because MLwiN has not yet been closed, or other software such as antivirus is holding the file open.

You only need to run the command:

Code: Select all

ssc install runmlwin, replace
once in order to install the software on your machine.

If a newer version of runmlwin is released then you can update to this using the command:

Code: Select all

adoupdate runmlwin, update
The global declaring where to find MLwiN:

Code: Select all

global MLwiN_path "C:\Program Files (x86)\MLwiN trial\i386\mlwin.exe"
only needs to be specified at the beginning of the session. If you don't want to specify this each time you can put it in your profile (see https://www.stata.com/help.cgi?profile).
hamzah734
Posts: 8
Joined: Sat Jan 06, 2018 7:48 pm

Re: How to replicate Stata do-file of MLRA using "runmlwin", please advise

Post by hamzah734 »

Dear Chris,

What are the differences between the command for a simple logistic regression model below

Code: Select all

*The code for a simple logistic regression model.
* run with IGLS
runmlwin psycmed cons male ib(first).agegroup poor, ///
		level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) ///
		mlwinsettings(optimat) nopause ///
		saveworksheet(IGLS_Simple_logistic_regression_analysis, replace)

* run MCMC using IGLS values as starting values
runmlwin psycmed cons male ib(first).agegroup poor, ///
		level2(neigh: cons) level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) ///
		mcmc(on) initsprevious mlwinsettings(optimat) nopause ///
		saveworksheet(MCMC_Simple_logistic_regression_analysis, replace)
and

Code: Select all

*Model s008 (to replicate MODEL 1 - Simple logistic regression analysis (psycmed cons male ib(first).agegroup poor))
* run with RIGLS to create starting values
runmlwin psycmed cons male ib(first).agegroup poor, ///
		level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) ///
		rigls mlwinsettings(optimat) nopause ///
		saveworksheet(S1-Model, replace) 
		
* run MCMC using the above
runmlwin psycmed cons male ib(first).agegroup poor, ///
		level1(id: ) discrete(distribution(binomial) link(logit) denom(cons)) ///
		mcmc(seed(13) burnin(5000) chain(10000)) initsprevious mlwinsettings(optimat) nopause ///
		saveworksheet(S2-Model, replace)
Is possible to copy paste equation at MLwiN worksheet into Microsoft word?

Thank you very much for your great feedback.
Based on your nice guidance the whole process of multilevel modelling of binary outcomes in two-levels succeeds run without face any matter.
Thank you again.

Best
Post Reply