Page 1 of 1

realcomImpute error

Posted: Mon Mar 19, 2012 2:32 pm
by Jamoo
Hi

Any ideas why I might be getting the 'in range not allowed' error when I use the realcomImpute command to export data from Stata to Realcom?

. realcomImpute deltabmi o.nq4sessions m.ethnic m.tenure m.singlepar m.empstat bmi1c idaci07 age1 sex nprogperpm nperprog towns villages built nq4sessions htroundbin wtroundbin using "Analysis\Change in BMI\dbmirealcom7.dat" ,numresponses(6) cons(cons) level2id(numprogid) replace

6 responses: deltabmi o.nq4sessions m.ethnic m.tenure m.singlepar m.empstat
12 auxiliary variables: bmi1c idaci07 age1 sex nprogperpm nperprog towns villages built nq4sessions htroundbin wtroundbin

in range not allowed

Re: realcomImpute error

Posted: Tue Mar 20, 2012 11:34 pm
by ChrisCharlton
From the output that you have provided it looks like it's having a problem in the following section of code:

Code: Select all

*save file ready for REALCOM to load
local stoppos = strpos("`using'",".")
if `stoppos'==0 {
	local savename `using'.txt
}
else {
	local savename `using'
}
file open myFile using `savename', write `replace'
file write myFile "`numresponses'" _n
local numauxvarstotal = `numauxvars'+2
file write myFile "`numauxvarstotal'" _n

file write myFile "`type1'"
forvalues i=2(1)`numresponses' {
	file write myFile _tab
	file write myFile "`type`i''"
}
file write myFile _n

*write variable names
local myvarlist `respvars_withoutprefix' `level2id' `cons' `auxvars'
tokenize `myvarlist'
local myvarlistlength = `numresponses' + 2 + `numauxvars'
file write myFile "`1'"
forvalues i=2(1)`myvarlistlength' {
	file write myFile _tab
	file write myFile "``i''"
}
file write myFile _n

*now write data
forvalues i=1(1)`numobs' {
	if `1'[`i']==. {
		file write myFile (-9.999e+029)
	}
	else {
		file write myFile (`1'[`i'])
	}
	forvalues j=2(1)`myvarlistlength' {
		if ``j''[`i']==. {
			file write myFile _tab (-9.999e+029)
		}
		else {
			file write myFile _tab (``j''[`i'])
		}
	}
	file write myFile _n
}

file close myFile
As these lines mostly appear to be related to writing to a file I would imagine that the most likely line to be the cause would be

Code: Select all

file open myFile using `savename', write `replace'
You can confirm this by running the command

Code: Select all

set trace on
prior to running the realcomImpute command. If this line is where the problem is occuring then there is probably a problem with the file name that you are specifying for saving the data. The first things I would try would be to specify either the full path, or with no path to see whether you still get the error.

Re: realcomImpute error

Posted: Wed Mar 21, 2012 11:21 am
by Jamoo
Dear Chris,

Thanks for the advice. I removed part of the file path and it worked - it was a very slight typo which I hadn't picked up by eyeballing the file path originally.

Good idea on the 'set trace on'. That might be a useful general note for people sending in error messages from Stata for the runmlwin forum too.

Best wishes

Jamie