Closed eivindhammers closed 7 years ago
reproduced ...
library(RStata)
db <- data.frame(x = c(letters[1:3], NA_character_))
(stata('gen y = !missing(x)', data.in = db, data.out = TRUE))
. gen y = !missing(x)
x y
1 a 1
2 b 1
3 c 1
4 NA 1
As you point out this is a foreign::write.dta
problem (anyway I think this should definitely be addressed); regarding haven for data IO i wrote some lines some time ago ( https://github.com/lbraglia/RStata/issues/1 ), i want to think about it...
not an RStata issue. closing
I have a
data.frame
with a character vector, which I use to generate an indicator variable in Stata, likeHowever,
stata()
converts my character vectorx
to a Stata string variablex
with NAs translated to "NA" instead of "", which I expected. Even though it's stated in?foreign::write.dta
that "missing values are handled correctly", this seems not to be the case for character vectors. May I suggest switching tohaven::write_dta
?