Alan Cobo-Lewis
2003-Oct-06 19:38 UTC
[R] Re: Use of the Foreign package to import Stata files
Long ago (Sat, 2 Nov 2002), Bill Hart <w.hart at sbcglobal.net> wrote:> An R newbie here. I am using R 1.6 currently and have > (successfully, I think) installed the Foreign package. > Tried to import a data file created with Stata 7.0 > SE. Had minor problems with syntax then R decided > that my file was not really a Stata file. It rejected > the file saying 'Not created by Stata 5-7/SE'. Any > suggestions on how to convince R that this is really, > truly a Stata file? >Thomas Lumley (tlumley at u.washington.edu) responded:> You need the version of read.dta that I wrote yesterday after finally > obtaining some 7/SE datasets for debugging. If you can compile packages > then I can send you the code, otherwise you will have to wait for the next > version of the foreign package.But sometimes older works better than newer. The read.dta() function in R 1.7.0's foreign package (package 0.6-3) fails to recognize as a Stata file what seems to be a genuine Stata file, even though R 1.6.2's foreign package (package 0.5-9) imports the same file just work fine. Using R 1.7 and rolling the package back to foreign 0.5 doesn't seem to fix the problem (haven't been able to roll R1.7 all the way back to foreign 0.5-9 yet, just to a newer 0.5 whose binary is still posted on cran). An example of such a Stata file it at http://www.ats.ucla.edu/stat/stata/examples/rwg/concord1.dta Does anyone have a hint or fix? alan -- Alan B. Cobo-Lewis, Ph.D. (207) 581-3840 tel Department of Psychology (207) 581-6128 fax University of Maine Orono, ME 04469-5742 alanc at maine.edu http://www.umaine.edu/visualperception
Thomas Lumley
2003-Oct-06 21:58 UTC
[R] Re: Use of the Foreign package to import Stata files
On Mon, 6 Oct 2003, Alan Cobo-Lewis wrote:> > But sometimes older works better than newer. The read.dta() function in > R 1.7.0's foreign package (package 0.6-3) fails to recognize as a Stata > file what seems to be a genuine Stata file, even though R 1.6.2's > foreign package (package 0.5-9) imports the same file just work fine. > Using R 1.7 and rolling the package back to foreign 0.5 doesn't seem to > fix the problem (haven't been able to roll R1.7 all the way back to > foreign 0.5-9 yet, just to a newer 0.5 whose binary is still posted on > cran). > > An example of such a Stata file it at > http://www.ats.ucla.edu/stat/stata/examples/rwg/concord1.dta >I don't know why it used to work. The file begins with 'h' (0x68), which isn't in my list of valid Stata file types. On the other hand, Stata has no problem with it. It's possible that it is a version 4 file (which would make sense, since version 5 file start with 'i' and increase from there) but that wouldn't explain why it used to work. With the stataread package (which predates 0.5-x of foreign) I get "Not a Stata version 5-7 data file". -thomas