RealcomImputeLoad error with import of impvals file

Welcome to the forum for REALCOM users. Feel free to post your question about REALCOM 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 REALCOM (Developing multilevel models for REAListically COMplex social science data) >> http://www.bristol.ac.uk/cmm/software/realcom/
Post Reply
Jamoo
Posts: 36
Joined: Wed Oct 05, 2011 2:33 pm

RealcomImputeLoad error with import of impvals file

Post by Jamoo »

Hi,

I'm having trouble with realcomImputeLoad.

The issue seems to be that Stata (using the realcomImputeLoad.ado) is not loading the impvals file in correctly - set trace shows this:

. realcomImputeLoad
------------------------------------------------------------------------------------------- begin realcomImputeLoad ---
- version 11.1
- syntax
- preserve
- quietly insheet using impvals.txt, clear
- local numimputations = v1[3]
v1 not found
--------------------------------------------------------------------------------------------- end realcomImputeLoad ---
r(111);

Examination of the impvals.txt file in Stata shows that it is reading in the variable names. This then means that v1 is no longer v1 but 'varname' and that row [3] is actually row [2].

I tried tinkering with a copy of the realcomImputeLoad.ado file, adding the 'nonames' option to the quietly insheet using impvals.txt, clear command. This worked in the sense that the first error was avoided, but the ado file then hung here instead:

. realcomImputeLoadJF
----------------------------------------------------------------------------------------- begin realcomImputeLoadJF ---
- version 11.1
- syntax
- preserve
- quietly insheet using impvals.txt, clear nonames
- local numimputations = v1[3]
- local i = 1
- local varname = v1 in 1
- while "`varname'"!="" {
= while "prepa1"!="" {
- local varname`i' `varname'
= local varname1 prepa1
- local i = `i' + 1
= local i = 1 + 1
- local varname = v`i' in 1
= local varname = v2 in 1
- }
- while "`varname'"!="" {
= while "prepa2"!="" {
- local varname`i' `varname'
= local varname2 prepa2
- local i = `i' + 1
= local i = 2 + 1
- local varname = v`i' in 1
= local varname = v3 in 1
- }
- while "`varname'"!="" {

******loop repeats for 21 response variables on first row of impvals

- while "`varname'"!="" {
= while "tenure"!="" {
- local varname`i' `varname'
= local varname20 tenure
- local i = `i' + 1
= local i = 20 + 1
- local varname = v`i' in 1
= local varname = v21 in 1
- }
- while "`varname'"!="" {
= while "singlepar"!="" {
- local varname`i' `varname'
= local varname21 singlepar
- local i = `i' + 1
= local i = 21 + 1
- local varname = v`i' in 1
= local varname = v22 in 1
v22 not found
}
------------------------------------------------------------------------------------------- end realcomImputeLoadJF ---
r(111);

At this point I got stuck as I'm not sure what the loop is doing (not sure what the 'in' means).

The interesting thing about all this is that it only seems to happen when there are more than 10 response variables in the impvals file (I tested this by removing the number of variable names). When there are less than 10, the nonames option is not needed and so the file runs fine.

I'd be grateful if you have any insights on this.

Best wishes

Jamie

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

Re: RealcomImputeLoad error with import of impvals file

Post by ChrisCharlton »

I don't know how Stata decides whether there are column names in the text file, but my guess would be that it bases it on whether there is a value in the first row for at least the number of subsequent columns. If you had created 10 imputed data sets then this would correspond with the value of 10 that you are seeing.

The 'in' is just referring to the row number of the chosen variable so:

Code: Select all

local varname = v22 in 1
is setting the local macro varname to the value of row 1in the variable v22.

It looks like the code is looping until it gets a blank variable name, which you won't get if you have more variable names than imputed data sets. A possible fix would be to add an extra tab to the end of the first line of impvals.txt so that this condition is met.

Jamoo
Posts: 36
Joined: Wed Oct 05, 2011 2:33 pm

Re: RealcomImputeLoad error with import of impvals file

Post by Jamoo »

Hi Chris,

Many thanks for the reply and helpful explanation of the 'in' syntax (it looks obvious in hindsight!)

I tried adding the extra space but unfortunately got no further with the problem.

Best wishes

Jamie

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

Re: RealcomImputeLoad error with import of impvals file

Post by ChrisCharlton »

You could either put the list of variables into a local macro and loop through that instead of generating possible variable names, e.g.

Code: Select all

unab varnames: *
or it might be worth comparing your version with the current one available when running:

Code: Select all

net from http://missingdata.lshtm.ac.uk/stata
I just had a look at the current version available there and one of the comments in the realcomImputeLoad.ado file is "bug fixed when number of responses exceeds number of imputations", so this might fix the issue you are seeing.

Jamoo
Posts: 36
Joined: Wed Oct 05, 2011 2:33 pm

Re: RealcomImputeLoad error with import of impvals file

Post by Jamoo »

Dear Chris,

Thanks for looking into this and pointing out the update. It was strange because I tried to force replace the ado files for realcomimpute before getting in touch on the forum. I had to manually delete the files and then reinstall the package to install the new files.

Anyway, problem is solved - thanks again for your invaluable help.

Best wishes

Jamie

Post Reply