Skip to content

read_dta can read labelled doubles but write_dta can't write labelled doubles #343

Closed

Description

library(haven)
library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 3.4.2
#> ── Attaching packages ────────────────────────────────── tidyverse 1.2.1 ──
#> ✔ ggplot2 2.2.1     ✔ purrr   0.2.4
#> ✔ tibble  1.3.4     ✔ dplyr   0.7.4
#> ✔ tidyr   0.7.2     ✔ stringr 1.2.0
#> ✔ readr   1.1.1     ✔ forcats 0.2.0
#> Warning: package 'tidyr' was built under R version 3.4.2
#> Warning: package 'purrr' was built under R version 3.4.2
#> Warning: package 'dplyr' was built under R version 3.4.2
#> ── Conflicts ───────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag()    masks stats::lag()

stata_dt <- read_dta("http://www.stata-press.com/data/r13/manuf.dta") %>% select(temperature, 
  chemical)

map_chr(stata_dt, typeof)
#> temperature    chemical 
#>    "double"    "double"
map_lgl(stata_dt, is.labelled)
#> temperature    chemical 
#>        TRUE        TRUE

write_dta(stata_dt, tempfile(fileext = ".dta"))
#> Error: Stata only supports labelled integers.
#> Problems: `temperature`, `chemical`

I'm not sure why write_dta is not allowed to save labelled doubles, although up to the previous version it was doing it just fine (at least in my work I've been saving labelled doubles, which were integers but read as doubles by read_dta). I understand that having labelled integers doesn't make sense but most of time labelled doubles are just integers that were read that way. @kuriwaki suggests that write_dta is allowed to save labelled doubles as long as they don't contain decimal points. See #326.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions