Reputation: 16488
A project that typically works on my Windows 7 office machine now gives errors on my Mac OS X laptop, trying to run it with R Studio. The part it fails is
library(foreign)
basis <- read.dta("myfile.dta")
Error in factor(rval[[v]], levels = tt[[ll[v]]], labels = names(tt[[ll[v]]])) :
invalid 'labels'; length 4 should be 1 or 3
R
and Rstudio
are on the newest version, I already ran update.packages()
. As I'm a beginner on R itself, I'm completely clueless what to try next.
Could this somehow be related with OS X encoding? The stata file has German "umlaut" (that is, non ISO characters) in it.
Upvotes: 2
Views: 1695
Reputation: 1422
Use package memisc
instead. This is supposed to be more flexible. From the docs (found here) we have:
The importer mechanism is more flexible and extensible than read.spss and read.dta of package "foreign", as most of the parsing of the file headers is done in R.
So back to the problem. First, load the following:
library(lattice)
library(MASS)
library(memisc)
and then use the call:
as.data.frame(as.data.set(Stata.file("filename.dta")))
Upvotes: 2