hydrosasa.blogg.se

Read stata 12 file in r
Read stata 12 file in r




read stata 12 file in r

for (i in 1:length(df))ĭf]] & amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp lt 0] & amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp lt - NA We now convert all three of these values to NA. Section 5.3 of the explanatory notes describes the encoding for this file: -1 (Don’t know), -2 (Refused) and -999 (Not stated). Read_dta automatically handles missing values in numeric and character variables. For categorical variables, missing values are typically encoded by negative numbers. Stata supports multiple types of missing values. For example, without having to look up the explanatory notes, we can see that variable a01 contains the responses to the question “A1: most important issue” and variable a02 contains the responses to “Best party on most important issue”. The first variable finalserialno is numeric (i.e., atomic), the third variable a01 is character, and the fourth variable a02 has a class of ‘labelled’ which can be converted to a factor or categorical variable (after we handle missing values).Įach variable has an associated label attribute to help with interpretation. The above output shows that the variables are already set to the correct types. attr(*, "names")= chr "Not stated" "Refused" "Don`t know" "None/No party". attr(*, "labels")= Named num NA NA NA 0 1 2 3 4 5 6. attr(*, "label")= chr "Best party on most important issue" attr(*, "label")= chr "A1: Most important issue" $ a01 : atomic nhs brexit society immigration.

read stata 12 file in r

#Read stata 12 file in r serial

attr(*, "label")= chr "Respondent Serial Number" attr(*, "label")= chr "Final Serial Number" This gives the following output: Classes ‘tbl_df’, ‘tbl’ and 'ame': 2194 obs. To check the properties of the data set we type str(df) The data set is now stored as a dataframe df with 357 variables. Read the Stata DTA file into R with two these two lines: library(haven)ĭf & amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp lt - read_dta("") The file contains 2017 face-to-face post-election survey responses along with explanatory notes.






Read stata 12 file in r