I used read_dta to import Stata files into R. I am trying to get rid of attr(,"format.stata") which seems to have been stored into a list.

I tried different things based on my google search but none of them have worked.

> df2$peer_id_spec[[1]] [1] 41 attr(,"format.stata") [1] "%9.0g" > df2$peer_id_spec <- zap_labels(zap_formats(df2$peer_id_spec)) > df2$peer_id_spec[[1]] [1] 41 attr(,"format.stata") [1] "%9.0g" > df2$peer_id_spec[[1]] [1] 41 attr(,"format.stata") [1] "%9.0g" > df2$peer_id_spec <- zap_formats(df2$peer_id_spec) > df2$peer_id_spec[[1]] [1] 41 attr(,"format.stata") [1] "%9.0g" > df2$peer_id_spec <- zap_formats(zap_labels(df2$peer_id_spec)) > df2$peer_id_spec[[1]] [1] 41 attr(,"format.stata") [1] "%9.0g" > df2$peer_id_spec <- zap_labels(zap_formats(df2$peer_id_spec)) > df2$peer_id_spec[[1]] [1] 41 attr(,"format.stata") [1] "%9.0g" 
2

1 Answer

Just delete them.

dta <- haven::read_dta(path) attributes(dta$sepallength) ## has format.stata attribute # $label # [1] "Sepal.Length" # # $format.stata # [1] "%9.0g" dta <- lapply(dta, `attr<-`, 'format.stata', NULL) ## delete attributes attributes(dta$sepallength) ## cleaned # $label # [1] "Sepal.Length" 

Alternatively use readstata13::read.dta13.

dta <- readstata13::read.dta13(path) attributes(dta$sepallength) ## no attributes # NULL 

Data:

path <- system.file("examples", "iris.dta", package = "haven") 
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.