Creating a level 2 variable from level 1 data

Welcome to the forum for MLwiN users. Feel free to post your question about MLwiN software 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!

Remember to check out our extensive software FAQs which may answer your question: http://www.bristol.ac.uk/cmm/software/s ... port-faqs/
Post Reply
drbris0769
Posts: 1
Joined: Tue Mar 26, 2013 11:27 pm

Creating a level 2 variable from level 1 data

Post by drbris0769 »

Hi there,

I am currently looking at a 2-level dataset of individuals nested in neighbourhoods.

I have information on each individual's ethnicity as a categorical level 1 predictor (Asian, Black, White), but would like to aggregate this information on each individual, to the neighbourhood level, to obtain the percentage of individual's for a particular neighbourhood that are white for example - thus forming a level 2 variable.

Is there any advice on how to go about this?
Kind Regards
ChrisCharlton
Posts: 1384
Joined: Mon Oct 19, 2009 10:34 am

Re: Creating a level 2 variable from level 1 data

Post by ChrisCharlton »

There may be better ways to do this, but here is one way that I believe you can achieve what you want (This assumes c100 to c103 are free in your worksheet, if not then substitute columns that are):

1) Create a zero/one variable indicating whether the record has the required characteristic. This can be done via the Data Manipulation->Calculate window or via a command (substituting the 1 for the category code that you're interested in):

Code: Select all

CALC c100="ethnicity"==1
2) Calculate the total number of units within each level 2 variable. This can be done via the Data Manipulation->Multilevel Data Manipulations window or via a command:

Code: Select all

MLCOunt "neighbourhood" c101
3) Calculate the number of units matching the category you are interested in. This can again be done via Data Manipulation->Multilevel Data Manipulations or the command:

Code: Select all

MLSum "neighbourhood" c100 c102
4) Use the results of the two calculations above to work out the average within each level 2 variable. This can be done via Data Manipulation->Calculate or the command:

Code: Select all

CALC c103 = (c102/c101) * 100
c103 should now contain the level 2 variable that you want and can be renamed to something appropriate.
Post Reply