Learn R Programming

misty (version 0.6.7)

read.dta: Read Stata DTA File

Description

This function calls the read_dta function in the haven package by Hadley Wickham, Evan Miller and Danny Smith (2023) to read a Stata DTA file.

Usage

read.dta(file, use.value.labels = FALSE, formats = FALSE, label = FALSE, labels = FALSE,
         missing = FALSE,   widths = FALSE, as.data.frame = TRUE, check = TRUE)

Value

Returns a data frame or tibble.

Arguments

file

a character string indicating the name of the Stata data file with or without file extension '.dta', e.g., "Stata_Data.dta" or "Stata_Data".

use.value.labels

logical: if TRUE, variables with value labels are converted into factors.

formats

logical: if TRUE (default), variable formats are shown in an attribute for all variables.

label

logical: if TRUE, variable labels are shown in an attribute for all variables.

labels

logical: if TRUE, value labels are shown in an attribute for all variables.

missing

logical: if TRUE, convert tagged missing values to regular R NA.

widths

logical: if TRUE, widths are shown in an attribute for all variables.

as.data.frame

logical: if TRUE (default), function returns a regular data frame; if FALSE function returns a tibble.

check

logical: if TRUE (default), argument specification is checked.

Author

Hadley Wickham and Evan Miller

References

Wickham H, Miller E, Smith D (2023). haven: Import and Export 'SPSS', 'Stata' and 'SAS' Files. R package version 2.5.3. https://CRAN.R-project.org/package=haven

See Also

read.sav, write.sav, read.xlsx, write.xlsx, read.mplus, write.mplus

Examples

Run this code
if (FALSE) {

read.dta("Stata_Data.dta")
read.dta("Stata_Data")

# Example 2: Read Stata data, convert variables with value labels into factors
read.dta("Stata_Data.dta", use.value.labels = TRUE)

# Example 3: Read Stata data as tibble
read.dta("Stata_Data.dta", as.data.frame = FALSE)
}

Run the code above in your browser using DataLab