title: Error reading Stata data in R
body: <p>I am trying to read a Stata dataset in R with the <code>foreign</code> package, but when I try to read the file using:</p>
  
  <pre><code>library(foreign)
  data &lt;- read.dta("data.dta")
  </code></pre>
  
  <p>I got the following error:</p>
  
  <pre><code>Error in read.dta("data.dta") : a binary read error occurred
  </code></pre>
  
  <p>The file works fine in Stata. This <a href="http://r.789695.n4.nabble.com/read-in-Stata-and-SPSS-with-value-labels-formats-td4311210.html" rel="nofollow">site</a> suggests saving the file in Stata without labels and then reading it into R. With this workaround I am able to load the file into R, but then I lose the labels. Why am I getting this error and how can I read the file into R with the labels? Another <a href="http://r.789695.n4.nabble.com/Read-dta-and-Write-dta-Binary-Data-Error-td4655754.html" rel="nofollow">person</a> finds that they get this error when they have variables with no values. My data do have at least one or two such variables, but I have no easy way to identify those variables in stata. It is a very large file with thousands of variables.</p>