Skip to content

Instantly share code, notes, and snippets.

@avallecam
Created December 12, 2018 03:17
Show Gist options
  • Save avallecam/d204f18bc5c415a96e168274b169532f to your computer and use it in GitHub Desktop.
Save avallecam/d204f18bc5c415a96e168274b169532f to your computer and use it in GitHub Desktop.
De R a STATA: errores por caracteres en nombres de columna
library(tidyverse)
library(haven)
library(labelled)
#crear data frame
set.seed(22)
dta <- data_frame("edad" = floor(rnorm(6,25,10)),
"sexo.per" = gl(2,1,6, labels = c("f","m")),
"grado_academico_a_nivel_nacional_" = rep(c("primaria",
"secundaria"),
each=3))
#regla
!grepl("^[A-Za-z_]{1}[A-Za-z0-9_]{0,31}$", names(dta))
#fuente:
#https://github.com/tidyverse/haven/blob/master/R/haven.R
#con error
dta %>% write_dta("data/test.dta")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment