Errors in batch assignment when .tab created in R

Hi there,

I’m hoping someone could help me with the following problem - perhaps someone else has come across this problem previously.

My team and I have been having difficulty performing batch upload interviews using collected data.

For context, we are doing a household survey which is performed in two stages. The first, a household listing exercise in an EA, and the second stage is an extend household interview based on a randomly selected sub-sample of those households from stage one that meet a certain set of criteria.

The sampling and the creation of the zip file which is to be upload to create the batch assignments are both performed in R. We get:

We do not get such errors when we export the .tab files in Stata - this only occurs when the .tab files are created in R using the write.table() function.

Checking the .tabs created in R following these errors, we don’t see where these issues are.

Has anyone else come across this problem previously? Any guidance would be most welcome - happy to share the .tab files if this would be helpful.

Thanks in advance.

The problem is undoubtedly with the .tab file that R is producing rather than with R per se.

For the SuSo part, if you haven’t already, please look at what the error messages mean. From there, you may be able to identify columns that are present (different) in R as compared to Stata.

For the R part–here I’m venturing into less comfortable territory–check whether your R method for writing tab files, write.table, has the same default behaviors as your successful Stata method (outsheet, export delimited, …?). To see differences, consider comparing what R and Stata produce via some difference engine. Separately, consider readr::write_tsv to produce tab-delimited files without needing to specify delimiters and other arguments in write.table.

If the above does not solve your issue, please produce a simple, reproducible example: some shareable data, some Stata code that produces the desired output, some R code that does produce the desired output.

Hello,

Thanks so much for your very helpful response - readr worked a treat.

As an aside, we noticed that write.table() creates a blank row in the .tab - do you think that this is causing the error(s)? This was the only difference that we could spot in the two .tabs created
Thanks

That sounds like it’s the problem, since SuSo wouldn’t know how to process missing values in IDs. Not sure why write.table is doing that, unless the eol argument prints an end-of-line marker even for the last line, resulting in a blank line at the end of the file