Skip to contents

This is a wrapper around haven::read_dta with some exception handling.

Usage

read_dta(file, id = NULL, filename = NULL, doi = NULL, .name_repair = "unique")

Arguments

file

A STATA file.

id

An identifier of the tibble, if omitted, defaults to the file name without its extension.

doi

An optional document object identifier.

.name_repair

Defaults to "unique" See tibble::as_tibble for details.

Value

A tibble. Variable labels are stored in the "label" attribute of each variable. It is not printed on the console, but the RStudio viewer will show it. `write_sav()` returns the input `data` invisibly.

Details

`read_dta()` reads both `.dta` files.

The funcion is not yet tested.

See also

Other import functions: pull_survey(), read_csv(), read_rds(), read_spss(), read_surveys()

Examples

# \donttest{
path <- system.file("examples", "iris.dta", package = "haven")
read_dta(path)
#> # A tibble: 150 × 6
#>    rowid   sepallength sepalwidth petallength petalwidth species
#>  * <chr>         <dbl>      <dbl>       <dbl>      <dbl> <chr>  
#>  1 iris_1         5.10       3.5         1.40      0.200 setosa 
#>  2 iris_2         4.90       3           1.40      0.200 setosa 
#>  3 iris_3         4.70       3.20        1.30      0.200 setosa 
#>  4 iris_4         4.60       3.10        1.5       0.200 setosa 
#>  5 iris_5         5          3.60        1.40      0.200 setosa 
#>  6 iris_6         5.40       3.90        1.70      0.400 setosa 
#>  7 iris_7         4.60       3.40        1.40      0.300 setosa 
#>  8 iris_8         5          3.40        1.5       0.200 setosa 
#>  9 iris_9         4.40       2.90        1.40      0.200 setosa 
#> 10 iris_10        4.90       3.10        1.5       0.100 setosa 
#> # … with 140 more rows
# }