UCLA Academic Technology Services HomeServicesClassesContactJobs

Frequently Asked Questions about MLwiN
How do I add a constant to my model?

We illustrate this using an example from page 47 of chapter 4 of Multilevel Analysis by Snijders and Bosker.  This example shows an intercept only model predicting langpost from the intercept.

Strategy 1: Point and Click

In order to include the intercept (constant) in the model, we need to create a new variable in the data file that is a column of 1s.  We can do this by choosing Data Manipulation then Generate Vector , which brings up the dialog box below. 

For the output column we click on a free column (in this case we chose c26) and then we pressed Control-N to rename it and then chose cons as the name of the variable.  Since the data file has 2287 observations, we put 2287 for the number of copies (if you do not remember how many observations are in your data file, choose Data Manipulation then Names). Since we wish the variable to have a value of 1, we put 1 as the value.  When we click Generate this creates a new variable that has 2287 rows and a value of 1 for each row. We should note that MLwiN does not give you any message indicating that it has created this new variable, but you can verify that it has been created by choosing Data Manipulation then Names. When done, you can close this window by clicking the X in the upper right corner.

Once we have created the variable cons we can then include it in our model by clicking Add Term in the Equations window.  We added cons as a new variable that was fixed, and varied randomly over level 1 and level 2.  The equations window then looked like this.

Strategy 2: Command Interface

If you wished to do this via the command interface (i.e. Data Manipulation then Command Interface you could type these commands.

name c26 "cons"
put 2287 1 "cons"

Strategy 3: Stata2MLwiN

If you are converting your data file from a Stata file (see How do I convert a Stata file to a MLwiN data file?), the program will automatically create a variable called cons (unless you already have such a variable or specify the nocons option when you run stata2mlwin.  This saves you the step of needing to create the constant within MLwiN.


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.