Error in foreign:read.dta(chainfile[i])

Welcome to the forum for R2MLwiN users. Feel free to post your question about R2MLwiN 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 to R2MLwiN: Running MLwiN from within R >> http://www.bris.ac.uk/cmm/software/r2mlwin/
Post Reply
wfleming
Posts: 11
Joined: Thu Aug 13, 2020 9:18 pm

Error in foreign:read.dta(chainfile[i])

Post by wfleming »

Having difficulty when estimating a two-level binomial logit with MCMC on a dataframe of 15k rows. I previously had no problem with this model but I'm coming back to it on a new system.

Model is:

Code: Select all

model <- runMLwiN(logit(outcome) ~ 1 + var1 + var2 + var3 + var4 + var5 + var6 + var7 +  (1 | L2id), 
               D = "Binomial", data = df, 
               estoptions = list(EstM = 1, mcmcMeth = list(burnin = 500, iterations = 5000)))
Error message is:
ECHO 0

error while obeying batch file C:/Users/William/AppData/Local/Temp/RtmpK0qjJ5/macrofile_8044d0d5325.txt at line number 465:
UNVE b1000 'parnum' 'itnum' 'mcmcchains' 'iteration' C2500 C2499 C2498 C2497 C2496 C2495 C2494 C2493 C2492 C2491 C2490 C2489 C2488 C2487 C2486 C2485 C2484 C2483 C2482 C2481 C2480 C2479 C2478 C2477 C2476 C2475 C2474 C2473 C2472 C2471 C2470 C2469 C2468 C2467
Column lengths do not match

error while obeying batch file C:/Users/William/AppData/Local/Temp/RtmpK0qjJ5/macrofile_8044d0d5325.txt at line number 465:
UNVE b1000 'parnum' 'itnum' 'mcmcchains' 'iteration' C2500 C2499 C2498 C2497 C2496 C2495 C2494 C2493 C2492 C2491 C2490 C2489 C2488 C2487 C2486 C2485 C2484 C2483 C2482 C2481 C2480 C2479 C2478 C2477 C2476 C2475 C2474 C2473 C2472 C2471 C2470 C2469 C2468 C2467

Column lengths do not match.
Execution completed

Error in foreign::read.dta(chainfile [ i ]) :
unable to open file: 'No such file or directory'
It then stops the execution and the model does not save.

It is able to complete estimation when very few predictors are specified (<5) but I receive this error as soon as I build it up. I've tried different dependent and independent variables, it doesn't seem to matter which are included. I've tried running it in debugmode and I can see the coefficients updating, it seems to finish with realistic estimates, and I am able to 'store' those estimates in the gui. If I press 'resume macro', I then receive the same error message of batch file & column lengths etc, in the MLwiN gui.

Any ideas?
wfleming
Posts: 11
Joined: Thu Aug 13, 2020 9:18 pm

Re: Error in foreign:read.dta(chainfile[i])

Post by wfleming »

I tracked it down to the missing values in one character variable, recoded it to factor and problem solved. This was exact code from a year or so ago, so not sure if it is a result of package update, R update or my data transfers. Perhaps stupid on my part as I thought I had checked this, but error message was very unhelpful here so will leave this post in case someone else has a similar problem.
ChrisCharlton
Posts: 1351
Joined: Mon Oct 19, 2009 10:34 am

Re: Error in foreign:read.dta(chainfile[i])

Post by ChrisCharlton »

Thanks for confirming that you have found the reason for the problem that you were encountering. When we send the data to MLwiN from R we do so via a Stata .dta file, which I don't believe has a representation for a character missing value. I'd have to look into exactly what is going on but I would imagine that this would result in any missing values being converted into an extra category within MLwiN. The error message that you received was from MLwiN unstacking the MCMC parameter chains into a column for each parameter, but without seeing the lengths (and possibly the content) of the columns involved I can't say exactly what was causing this.
Post Reply