Page 1 of 2
Problem getting residuals: after merge, not all observations
Posted: Tue May 01, 2012 8:34 pm
by ewancarr
I'm running the latest version of runmlwin (as of 1st May). When I ask for residuals from the following model:
Code: Select all
runmlwin affect cons w2 w3 ///
timep notfit physical ///
hoursgm ///
agegm female i.income partner children notcitz ///
i.nace4 i.size everuni i.isco4, ///
level2(countid: cons timep, residuals(u)) level1(pid: , weightvar(weight)) ///
discrete(distribution(binomial) link(logit) denominator(cons) pql2) ///
nopause or
I get the error message:
merge: after merge, not all observations from master or matched
(merged result left in memory)
Anything I can do about this? The residuals still appear to be be saved, but the above error will stop a .do file from running (and is slightly worrying).
Many thanks,
Ewan
--
Re: Problem getting residuals: after merge, not all observat
Posted: Tue May 01, 2012 9:30 pm
by ChrisCharlton
It's hard to say exactly what's going wrong here without the data, however we have seen this message before where each unit at a level didn't have a unique id (
http://www.cmm.bristol.ac.uk/forum/view ... ?f=3&t=419). Could you please confirm whether each value of countid is unique to only one level 2 unit?
Have you looked at the values of the residuals brought back, and if so do they look sensible? If you also check the number of unique residual values then in general they should match the number of level 2 units in the model.
Re: Problem getting residuals: after merge, not all observat
Posted: Wed May 02, 2012 4:31 pm
by GeorgeLeckie
Hi Ewan and Chris,
Looking at the previous post on this issue, I think the problem relates to not using a unique identifier at level-1. So the problem may lie with pid (rather than with countid).
So try generating a new level-1 ID and using this in your model
Code: Select all
sort countid pid
generate atomicid = _n
Best wishes
George
Re: Problem getting residuals: after merge, not all observat
Posted: Thu May 03, 2012 12:51 am
by ewancarr
Thanks for getting back to me.
Chris: The residuals I'm getting back do look sensible. However, with regard to unique IDs: the data is really a 3-level repeated cross-sectional structure:
Level 3: Country (N = 31)
Level 2: Wave (N = 3)
Level 1: Individual (N = 90,000ish)
I had previously been modelling this using a 3-level structure, but found the results didn't change if I used the simpler 2-level model, and included dummy variables for "wave2" and "wave3". So yes, countid is not unique -- it also varies by wave. Is this a problem?
George: generating a new level-1 ID didn't help.
Thanks!
Ewan
--
Re: Problem getting residuals: after merge, not all observat
Posted: Thu May 03, 2012 8:05 am
by GeorgeLeckie
Hi Ewan,
So the identifiers for your three potential levels look like this
C W I
1 1 1
1 1 2
1 2 3
1 2 4
1 3 5
1 3 6
2 1 7
2 1 8
2 2 9
2 2 10
2 3 11
2 3 12
But you only fit a two-level model for individuals-within-countries so the data which is actually sent to MLwiN look like this
C I
1 1
1 2
1 3
1 4
1 5
1 6
2 7
2 8
2 9
2 10
2 11
2 12
and you still get the error message. I am not sure why this is. Please email us the data and do-file to replicate this problem
George
Re: Problem getting residuals: after merge, not all observat
Posted: Thu May 03, 2012 8:35 am
by ChrisCharlton
MLwiN calculated residuals in a short form with one row per level 2 unit, i.e.
Code: Select all
countid|residual
-------+---------
1 | 0.2
2 | 0.3
we then merge this back into the original data (if I remember correctly using the level identifier).
If your level identifier isn't unique for each unit of that level, i.e.
Code: Select all
countid|id
-------+------
1 | 1
1 | 2
2 | 3
2 | 4
1 | 5
1 | 6
then merge won't be able match the residuals back to the original data correctly.
This is what I was thinking might be happening in your case, but I'll need to check the runmlwin code to make sure that this is the merge we are doing.
Re: Problem getting residuals: after merge, not all observat
Posted: Thu May 03, 2012 10:59 am
by GeorgeLeckie
Hi Chris,
But runmlwin should issue an error message if the data are not sorted acording to the model implied hierarchy
George
Re: Problem getting residuals: after merge, not all observat
Posted: Thu May 03, 2012 11:36 am
by ChrisCharlton
I've just tested this with the tutorial dataset by recoding some of the schools, and you're right. I get the following message before it tries to fit the model:
The data must be sorted according to the order of the model hierarchy: school student.
So I guess that eliminates that as a possible cause.
Re: Problem getting residuals: after merge, not all observat
Posted: Thu May 03, 2012 4:07 pm
by ewancarr
George — I've emailed you the dataset and do-file.
Many thanks,
Ewan
--
Re: Problem getting residuals: after merge, not all observat
Posted: Thu May 03, 2012 5:33 pm
by GeorgeLeckie
Hi Ewan,
Thanks for sending the data and do-file to replicate your problem.
You have found a bug! The problem relates to having missing values for your level-2 ID.
We have implemented a solution to this bug which will be available in the next release of runmlwin.
So that you can proceed with your research, a simple workaround is to simply listwise delete your level-2 IDs before you issue the runmlwin command. So just type the following before running runmlwin
But to be really safe, I would listwise delete all variables which appear anywhere in the runmlwin command.
Please try this and let us know whether this workaround solves your problem.
I hope this helps
George