***************************************************************************** * Stata do-file to replicate results given in the following presentation: * * TITLE: Running MIXREGLS from within Stata: The runmixregls command * AUTHORS: George Leckie * LOCATION: Bristol * DATE: 27-06-2013 * * George Leckie * Centre for Multilevel Modelling, 2013 ***************************************************************************** * To run this do-file in Stata you must be working with: * * (1) Stata 12.0 or higher * * (2) The latest version of MIXREGLS * * (3) The latest version of the runmixregls command * * * You must also tell runmixregls where MIXREGLS is installed. One way you can * do this is by specifying the MLwiN path by defining a global macro called * mixreglspath. For example: * * . global mixreglspath "C:\MIXREGLS\mixreglsb.exe" * * See the "Remarks on using runmixregls for the first time" section of the * runmixregls help file for further information: * * . help runmixregls * ***************************************************************************** * Install the runmixregls command from the Statistical Software Components * (SSC) archive //ssc install runmixregls * Specify the file address for mlwin.exe on your computer as the global * macro mixreglspath global mixreglspath "C:\Users\gl9158\MIXREGLS\mixreglsb.exe" **************************************************************************** * Example - Riesby depression data **************************************************************************** * Load the Riesby data into memory use "http://www.bristol.ac.uk/cmm/media/runmixregls/reisby", clear * Describe the data contents codebook, compact * Drop cases with missing response recode hamdep (-9=.) * Declare the data to be panel data xtset id * Plot a Spaghetti plot of the observed data twoway (line hamdep week, connect(ascending)), xlabel(0(1)5) by(endog) * Fit the model (cf Hedeker and Nordgren, 2013, page 16) runmixregls hamdep week endog endweek, between(endog) within(week endog) * Store the estimation results estimates store ex1m1 * Refit the model specifying the reffects() and residuals() options to * retrieve the standardized EB random effects and residuals, respecitvely * Also specify the iterate() option to specify the maximum number of * iterations to be 100. Specify the noheader option to suppress the * table header. runmixregls hamdep week endog endweek, between(endog) within(week endog) /// association(none) reffects(theta1 theta2) residuals(estd) /// iterate(100) noheader * Store the estimation results estimates store ex1m2 * Figure 1 scatter theta2 theta1 * Figure 2 histogram estd, width(0.5) start(-3) frequency * LR test comparing Model 1 and 2 lrtest ex1m1 ex1m2 * Wald test for whether the two patient groups differ significantly or not test endog endweek * Calculate the Scale variance nlcom (sigma2_v: [Scale]sigma^2) **************************************************************************** exit