Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FRONTUR #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
importFrom("readr", "read_fwf", "fwf_widths")
importFrom("readr", "read_fwf", "fwf_widths", "read_csv2")
importFrom("utils", "read.table")

export(epa2005, test.metadata, defun2011, ees2010,
censo2010, epf.2011.gastos, epf.2011.hogares,
epf.2011.miembros, padron2016)
epf.2011.miembros, padron2016, frontur2016)
45 changes: 45 additions & 0 deletions R/frontur2016.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#' Download data from the "Frontur"
#'
#' This function downloads data from the Spanish "FRONTUR" using the information provided by the Spanish Statistical Office (INE).
#'
#' @param file Character string with the name of the microdata file provided by the INE on the
#' \href{http://www.ine.es/dyngs/INEbase/es/operacion.htm?c=Estadistica_C&cid=1254736176996&menu=resultados&secc=1254736195382&idp=1254735576863}{FRONTUR} section. It allows either a path to a file,
#' or literal data (single string or raw vector). It also allows compressed files in \code{.gz}, \code{.bz2}, \code{.xz}, or \code{.zip} format.
#'
#' @return \code{\link[tibble]{tibble}} with all avaliable requested data where each row corresponds to an anonymised citizen.
#' @details This function reads microdata from the members approach of the "Padrón" in Spain. It was originally built using the metadata for 2016 file but it may be used for later years. Previous files have a different, non compatible, format.
#'
#' @author David Carrasco.
#' @note The \code{file} parameter allows any flat file with fixed width.
#' @references http://www.ine.es/prodyser/microdatos.htm
#' @examples
#' \dontrun{
#' raw <- frontur2016("sample_frontur_2016.txt")
#' summary(raw)
#' }
#' @seealso \code{\link[read_fwf]{readr}} to read fixed width files.


###################################################################
# David-Carrasco
# 20190327
# Reads the "frontur" microdata in its 2016 (and probably others) version
###################################################################

frontur2016 <- function(file){

mdat.1 <- read.table(system.file("metadata", "frontur_2016_mdat1.txt", package = "MicroDatosEs"),
header = T, sep = "\t",
fileEncoding = "UTF-8",
stringsAsFactors = FALSE)

suppressMessages(
dat <- read_csv2(file, col_names = mdat.1$var, skip=1, col_types = "ccccccccccc")
)

read.fwf.microdata(dat,
system.file("metadata", "frontur_2016_mdat1.txt", package = "MicroDatosEs"),
system.file("metadata", "frontur_2016_mdat2.txt", package = "MicroDatosEs"),
fileEncoding = "UTF-8")
}

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ It is intended mostly for microdata which is generated periodically with the sam
* **Mortality** (Annual deaths in Spain): unfortunately, public microdata does not include the cause of death.
* **EPF** (Encuesta de presupuestos familiares)
* **Padrón**
* **Frontur**

## Use cases and examples

Expand Down
17 changes: 17 additions & 0 deletions inst/extdata/sample_frontur_2016.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
A0;A0_1;A0_7;A1;Residencia;CCAA;A14;A15;A16;A13_1;Factor
1;20181101031507;2;2;13;09;2;1;6;6;99.623143409
1;20181100031507;2;2;13;09;2;1;6;6;99.623143409
1;20181100017107;2;2;13;04;1;2;6;4;25.519607901
1;20181100018507;3;2;13;98;0;1;6;1;385.55899129
1;20181100012913;2;2;13;09;8;1;6;6;163.65133432
1;20181100006388;3;2;13;98;0;1;6;1;104.04387009
1;20181100013667;2;2;13;13;1;1;6;5;82.442475534
1;20181100006386;2;2;13;09;1;2;6;6;75.085969225
1;20181000010082;3;2;13;09;0;1;6;1;113.5132676
1;20181100003142;2;2;13;09;1;1;6;3;91.108450254
2;20181100002871;2;2;13;04;1;1;1;5;25.616372281
2;20181102002874;2;2;13;04;2;1;6;4;53.69196178
1;20181101004187;2;2;13;09;1;1;6;4;167.02122322
2;20181101002876;2;2;13;04;1;1;6;3;25.637361136
1;20181100000882;2;2;13;09;6;1;6;4;284.5585924
2;20181105003208;2;2;13;09;1;1;6;4;264.70615886
12 changes: 12 additions & 0 deletions inst/metadata/frontur_2016_mdat1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var start end width descr
A0 1 1 1 Encuesta de procedencia
A0_1 2 15 14 Identificador cuestionario
A0_7 16 16 1 Tipo de viajero
A1 17 17 1 Vía de Entrada de los turistas
Residencia 18 19 2 Pais de residencia habitual
CCAA 20 21 2 Comunidad Autónoma de destino principal del viaje
A14 22 22 1 Alojamiento principal
A15 23 23 1 Motivo del viaje
A16 24 24 1 Utilización de paquete turístico
A13_1 25 25 1 Duración del viaje
Factor 26 37 12 Factor de elevación de la encuesta
72 changes: 72 additions & 0 deletions inst/metadata/frontur_2016_mdat2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"var" "tipo" "nulo" "llave" "valor"
"A0" "D" NA "1" "FRONTUR"
"A0" "D" NA "2" "EGATUR"
"A0_1" "D" NA NA ""
"A0_7" "D" NA "2" "Turista no residente"
"A0_7" "D" NA "3" "Excursionista No Residente"
"A1" "D" NA "1" "Carretera"
"A1" "D" NA "2" "Aeropuerto"
"A1" "D" NA "3" "Ferry/Barco"
"A1" "D" NA "4" "Tren"
"Residencia" "D" NA "1" "Alemania"
"Residencia" "D" NA "2" "Bélgica"
"Residencia" "D" NA "3" "España"
"Residencia" "D" NA "4" "Francia"
"Residencia" "D" NA "5" "Irlanda"
"Residencia" "D" NA "6" "Italia"
"Residencia" "D" NA "7" "Países Bajos"
"Residencia" "D" NA "8" "Portugal"
"Residencia" "D" NA "9" "Reino Unido"
"Residencia" "D" NA "10" "Países Nordicos"
"Residencia" "D" NA "11" "Rusia"
"Residencia" "D" NA "12" "Suiza"
"Residencia" "D" NA "13" "Resto de Europa"
"Residencia" "D" NA "14" "Estados Unidos de América"
"Residencia" "D" NA "15" "América (sin EEUU)"
"Residencia" "D" NA "16" "Resto del mundo"
"CCAA" "D" NA "01" "Andalucía"
"CCAA" "D" NA "02" "Aragón"
"CCAA" "D" NA "03" "Principado de Asturias"
"CCAA" "D" NA "04" "Baleares"
"CCAA" "D" NA "05" "Canarias"
"CCAA" "D" NA "06" "Cantabria"
"CCAA" "D" NA "07" "Castilla y León"
"CCAA" "D" NA "08" "Castilla La Mancha"
"CCAA" "D" NA "09" "Cataluña"
"CCAA" "D" NA "10" "Com.Valenciana"
"CCAA" "D" NA "11" "Extremadura"
"CCAA" "D" NA "12" "Galicia"
"CCAA" "D" NA "13" "Com.Madrid"
"CCAA" "D" NA "14" "Región de Murcia"
"CCAA" "D" NA "15" "C.F.Navarra"
"CCAA" "D" NA "16" "País Vasco"
"CCAA" "D" NA "17" "La Rioja"
"CCAA" "D" NA "18" "Ceuta"
"CCAA" "D" NA "19" "Melilla"
"CCAA" "D" NA "98" "Transito"
"A14" "D" NA "1" "Hoteles y Similares"
"A14" "D" NA "2" "Alojamiento alquiler"
"A14" "D" NA "3" "Camping"
"A14" "D" NA "4" "Casa rural"
"A14" "D" NA "5" "Crucero"
"A14" "D" NA "6" "Otro alojamiento mercado"
"A14" "D" NA "7" "Vivienda en propiedad"
"A14" "D" NA "8" "Vivienda familiares/amigos"
"A14" "D" NA "9" "Otro alojamiento no mercado"
"A14" "D" NA "0" "No procede"
"A15" "D" NA "0" "No procede"
"A15" "D" NA "1" "Ocio/vacaciones"
"A15" "D" NA "2" "Negocios"
"A15" "D" NA "3" "Estudios"
"A15" "D" NA "4" "Personal (salud, familia)"
"A15" "D" NA "5" "Otros motivos"
"A16" "D" NA "1" "Sí"
"A16" "D" NA "6" "No"
"A16" "D" NA "0" "No procede"
"A13_1" "D" NA "1" "Ninguna noche"
"A13_1" "D" NA "2" "1 noche"
"A13_1" "D" NA "3" "De 2 a 3 noches"
"A13_1" "D" NA "4" "De 4 a 7 noches"
"A13_1" "D" NA "5" "De 8 a 15 noches"
"A13_1" "D" NA "6" "Más de 15 noches"
"Factor" "N" NA NA ""
42 changes: 42 additions & 0 deletions man/frontur2016.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.