[R] Help in running Stata dataset in R

Lazarus Mramba LMramba at kilifi.kemri-wellcome.org
Wed Aug 6 12:06:21 CEST 2008


Dear Prof Brian,

It is true that i used the epicalc package. The functions use() and
des() are from epicalc. 
The problem does not occur if i use library(foreign) : tmp <-
read.dta("maltreat.dta", convert.dates=FALSE)
 
>  sessionInfo() 
R version 2.7.1 (2008-06-23) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] splines   stats     graphics  grDevices utils     datasets  methods
 
[8] base     

other attached packages:
[1] epicalc_2.7.1.2 survival_2.34-1 foreign_0.8-26 


 library(foreign)
> tmp <- read.dta("maltreat.dta", convert.dates=FALSE)
> str(tmp)
'data.frame':   670 obs. of  43 variables:

## thanks. able to read the dataset. 
However, epicalc function use() cannot call the data.

library(epicalc)
> use("maltreat.dta")
Error in fromchar(x) : 
  character string is not in a standard unambiguous format


 use("malvac.dta")
Error in fromchar(x) : 
  character string is not in a standard unambiguous format


## I have attached the two datasets herein





Kind regards,
Lazarus Mramba
Junior Statistician
P.O Box 986, 80108,
Kilifi, Kenya
Mobile No. +254721292370
Tel: +254 41 522063
Tel: +254 41 522390
(office extension : 419)

>>> Prof Brian Ripley <ripley at stats.ox.ac.uk> 08/06 12:38 PM >>>
What are use() and des()?  Please note the footer of this message.
(Are you using package epicalc without telling us?)

I suspect that foreign::read.dta is being used.  That has argument 
'convert.dates', and you could try setting it to FALSE, as the message
is 
from as.Date.character() complaining about the date format.

It is likely that the difference is in the version of 'foreign' and not
in 
the version of R: the posting guide asked for the output of
sessionInfo() 
which would have told us which versions these were.

In short, try

library(foreign)
tmp <- read.dta("maltreat.dta", convert.dates=FALSE)
str(tmp)
tmp$dob
tmp$todaydate

and if the latter two are numbers, try converting them by e.g.

as.Date(tmp$dob, origin="1960-01-01")

It would help to make the dataset available for the developers to 
investigate.

On Wed, 6 Aug 2008, Lazarus Mramba wrote:

> Dear All,
>
> I installed R 2.7.0 and tried to call a dataset i had ealier own
called
> on R2.6.2 but i keep on getting an error:
> use("maltreat.dta")
>
> Error in fromchar(x) :
>  character string is not in a standard unambiguous format
>
> Tried doing the same with R2.7.1 but i get the same error.
>
> However if i call the same on R 2.6.2, there is no error:
>
> use("maltreat.dta")
>> des()
>
> No. of observations =  670
>   Variable          Class           Description
> 1  scrno             integer
> 2  todaydate         Date
> 3  ethnic            character
> 4  othtribe          character
> 5  dob               Date
> 6  ageyrs            integer
> 7  agemths           integer
> 8  sex               character
>
> I cannot figure out what the problem is.
>
> Please help me.
>
>
>
> Kind regards,
> Lazarus Mramba
> Junior Statistician
> P.O Box 986, 80108,
> Kilifi, Kenya
> Mobile No. +254721292370
> Tel: +254 41 522063
> Tel: +254 41 522390
> (office extension : 419)
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help 
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk 
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/ 
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list