Title: | Utilities for Official Spanish Microdata |
---|---|
Description: | Provides utilities for reading and processing microdata from Spanish official statistics with R. |
Authors: | Carlos J. Gil Bellosta [aut, cre], Carlos Neira [ctb], Diego Paniagua Sánchez [ctb], Fiorella Mori Peláez [ctb], Jorge López Pérez [ctb], Estitxu Villamor [ctb], José Luis Cañadas Reche [ctb] |
Maintainer: | Carlos J. Gil Bellosta <[email protected]> |
License: | GPL-3 |
Version: | 0.8.15 |
Built: | 2024-08-20 02:28:12 UTC |
Source: | https://github.com/rOpenSpain/MicroDatosEs |
This function downloads the data from 2010 (or later) Spanish Census using the information provided by the Spanish Statistical Office (INE).
censo2010(file)
censo2010(file)
file |
Character string with the name of the microdata file provided by the INE on the
Census section. It allows either a path to a file,
or literal data (single string or raw vector). It also allows compressed files in |
This function reads microdata from the 2010 census in Spain. It was originally built using the metadata for 2010 file but it may be used for later years.
Note that the loaded object will be of considerable size and may require a computer from 8 GB of RAM. In order to avoid this kind of computational issues, you can also download the splitted version provided by the INE.
tibble
with all avaliable requested data where each row corresponds to an anonymised citizen.
The file
parameter allows any flat file with fixed width.
Carlos Neira and Carlos J. Gil Bellosta
http://www.ine.es/prodyser/microdatos.htm
read_fwf
to read fixed width files.
# Downloaded \href{ftp://www.ine.es/temas/censopv/cen11/Microdatos_personas_nacional.zip}{data} ## Not run: raw <- censo2010("MicrodatosCP_NV_per_nacional_3VAR.txt") summary(raw) ## End(Not run)
# Downloaded \href{ftp://www.ine.es/temas/censopv/cen11/Microdatos_personas_nacional.zip}{data} ## Not run: raw <- censo2010("MicrodatosCP_NV_per_nacional_3VAR.txt") summary(raw) ## End(Not run)
This function downloads deaths statistcs from the Spanish Statistical Office (INE).
defun2011(file)
defun2011(file)
file |
Character string with the name of the microdata file provided by the INE on the
Deaths section. It allows either a path to a file
or literal data (single string or raw vector). It also allows compressed files in |
This function reads deaths microdata in Spain.
It was originally built using the metadata for the 2011 file and may work with microdata files for other yearly submissions. Previous files have a different, non compatible, format.
tibble
with all avaliable requested data where each row corresponds to an anonymised citizen.
The file
parameter allows any flat file with fixed width.
Carlos J. Gil Bellosta
http://www.ine.es/prodyser/microdatos.htm
read_fwf
to read fixed width files.
## Not run: raw <- defun2011("datos_2016.zip") # It will be automatically uncompressed. summary(raw) ## End(Not run)
## Not run: raw <- defun2011("datos_2016.zip") # It will be automatically uncompressed. summary(raw) ## End(Not run)
This function downloads data from the Spanish Survey of Salary Structure using the information provided by the Spanish Statistical Office (INE).
ees2010(file)
ees2010(file)
file |
Character string with the name of the microdata file provided by the INE on the
EES section. It allows either a path to a file,
or literal data (single string or raw vector). It also allows compressed files in |
This function reads microdata from the Survey of Salary Structure in Spain. It was originally built using the metadata for 2010 file but it may be used for later years. Previous files have a different, non compatible, format.
tibble
with all avaliable requested data where each row corresponds to an anonymised citizen.
The file
parameter allows any flat file with fixed width.
Carlos J. Gil Bellosta, with major contributions from José Luis Cañadas Reche
http://www.ine.es/prodyser/microdatos.htm
read_fwf
to read fixed width files.
## Not run: raw <- ees2010("datos_2014.zip") # It will be automatically uncompressed. summary(raw) ## End(Not run)
## Not run: raw <- ees2010("datos_2014.zip") # It will be automatically uncompressed. summary(raw) ## End(Not run)
This function downloads the data from the Spanish Active Population Survey using the information provided by the Spanish Statistical Office (INE).
epa2005(file)
epa2005(file)
file |
Character string with the name of the microdata file provided by the INE on the
EPA section. It allows either a path to a file,
or literal data (single string or raw vector). It also allows compressed files in |
This function reads microdata from the quarterly Active Population Survey in Spain. It was originally built using the metadata for 2005 file but it may be used for later years. Previous files have a different, non compatible, format.
tibble
with all avaliable requested data where each row corresponds to an anonymised citizen.
The file
parameter allows any flat file with fixed width.
Carlos J. Gil Bellosta
http://www.ine.es/prodyser/microdatos.htm
read_fwf
to read fixed width files.
## Not run: raw <- epa2005("EPA4T017") summary(raw) ## End(Not run)
## Not run: raw <- epa2005("EPA4T017") summary(raw) ## End(Not run)
This function downloads data from the Spanish Survey of Family Budgets (Expenditure approach) using the information provided by the Spanish Statistical Office (INE).
epf.2011.gastos(file)
epf.2011.gastos(file)
file |
Character string with the name of the microdata file provided by the INE on the
EPF section. It allows either a path to a file,
or literal data (single string or raw vector). It also allows compressed files in |
This function reads microdata from the expenditure approach of the Survey of Family Budgets in Spain. It was originally built using the metadata for 2011 file but it may be used for later years. Previous files have a different, non compatible, format.
tibble
with all avaliable requested data where each row corresponds to an anonymised citizen.
The file
parameter allows any flat file with fixed width.
Diego Paniagua Sánchez and Carlos J. Gil Bellosta
http://www.ine.es/prodyser/microdatos.htm
read_fwf
to read fixed width files.
## Not run: raw <- epf.2011.gastos("sample_gastos_a2011.txt") summary(raw) ## End(Not run)
## Not run: raw <- epf.2011.gastos("sample_gastos_a2011.txt") summary(raw) ## End(Not run)
This function downloads data from the Spanish Survey of Family Budgets (Homes approach) using the information provided by the Spanish Statistical Office (INE).
epf.2011.hogares(file)
epf.2011.hogares(file)
file |
Character string with the name of the microdata file provided by the INE on the
EPF section. It allows either a path to a file,
or literal data (single string or raw vector). It also allows compressed files in |
This function reads microdata from the homes approach of the Survey of Family Budgets in Spain. It was originally built using the metadata for 2011 file but it may be used for later years. Previous files have a different, non compatible, format.
tibble
with all avaliable requested data where each row corresponds to an anonymised citizen.
The file
parameter allows any flat file with fixed width.
Diego Paniagua Sánchez and Carlos J. Gil Bellosta
http://www.ine.es/prodyser/microdatos.htm
read_fwf
to read fixed width files.
## Not run: raw <- epf.2011.gastos("sample_hogares_a2011.txt") summary(raw) ## End(Not run)
## Not run: raw <- epf.2011.gastos("sample_hogares_a2011.txt") summary(raw) ## End(Not run)
This function downloads data from the Spanish Survey of Family Budgets (Members approach) using the information provided by the Spanish Statistical Office (INE).
epf.2011.miembros(file)
epf.2011.miembros(file)
file |
Character string with the name of the microdata file provided by the INE on the
EPF section. It allows either a path to a file,
or literal data (single string or raw vector). It also allows compressed files in |
This function reads microdata from the members approach of the Survey of Family Budgets in Spain. It was originally built using the metadata for 2011 file but it may be used for later years. Previous files have a different, non compatible, format.
tibble
with all avaliable requested data where each row corresponds to an anonymised citizen.
The file
parameter allows any flat file with fixed width.
Diego Paniagua Sánchez and Carlos J. Gil Bellosta
http://www.ine.es/prodyser/microdatos.htm
read_fwf
to read fixed width files.
## Not run: raw <- epf.2011.gastos("sample_miembros_a2011.txt") summary(raw) ## End(Not run)
## Not run: raw <- epf.2011.gastos("sample_miembros_a2011.txt") summary(raw) ## End(Not run)
This function downloads data from the Spanish "padrón" using the information provided by the Spanish Statistical Office (INE).
padron2016(file)
padron2016(file)
file |
Character string with the name of the microdata file provided by the INE on the
Padrón section. It allows either a path to a file,
or literal data (single string or raw vector). It also allows compressed files in |
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.
tibble
with all avaliable requested data where each row corresponds to an anonymised citizen.
The file
parameter allows any flat file with fixed width.
Carlos J. Gil Bellosta; metadata provided by Fiorella Mori.
http://www.ine.es/prodyser/microdatos.htm
read_fwf
to read fixed width files.
## Not run: raw <- epf.2011.gastos("sample_padron_2016.txt") summary(raw) ## End(Not run)
## Not run: raw <- epf.2011.gastos("sample_padron_2016.txt") summary(raw) ## End(Not run)
This function reads a microdata file based on metadata provided by the user. It is particularly intended for the user to test the metadata before submitting it for inclusion in the package.
test.metadata(file, md.1, md.2, encoding = "UTF-8" )
test.metadata(file, md.1, md.2, encoding = "UTF-8" )
file |
The name of the microdata file |
md.1 |
First metadata file |
md.2 |
Second metadata file |
encoding |
Either 'latin1' or 'UTF-8', the encoding used in the metadata files |
The function reads the microdata file using two standardized metadata files. For some microdata files, the package provides the required metadata files; however, users may be willing to load other microdata files using the package infrastructure or test metadata files before providing them to the maintainer for inclusion in it.
The first metadata file deals with columns. It is a tab-separated file with five columns. The first one contains the column name. Columns 2-4, the position where the column data starts and ends and its length. The last field is the column label.
The second metadata file deals with the column contents. It is also a tab separated file with five columns. The first one is the column name.
The second one indicates the column type. There are two main types: "D" for dictionary and "N" for numeric. Dictionary columns require a map from keys to values (columns 4 and 5): values read in the key column will be replaced by the value column content. These columns can be left empty for numeric columns. The third column deals with options in case NULL/NA values are found. There are other specialized column types not documented here. Adding new specialized column types requires changing the inner code of other functions.
The third column indicates which code does the column use for NA values (in case, say, NULL values are marked with "."). Occurrences of such code will be replaced with NA in the final table.
Note that the metadata files need to be stored in UTF-8 encoding.
The example section of this document shows the contents of a set of metadata files.
A data.frame
.
Carlos J. Gil Bellosta
# This command reads a few lines sampled from # the EPA for 2011Q1 x <- test.metadata(system.file("extdata", "sampleEPA0111.txt", package = "MicroDatosEs"), system.file("metadata", "epa_mdat1.txt", package = "MicroDatosEs"), system.file("metadata", "epa_mdat2.txt", package = "MicroDatosEs")) # Example of first metadata file mdat1_example <- read.table(system.file("metadata", "epa_mdat1.txt", package = "MicroDatosEs"), header = TRUE, sep = "\t", fileEncoding = "UTF-8", stringsAsFactors = FALSE) head(mdat1_example) # Example of second metadata file mdat2_example <- read.table(system.file("metadata", "epa_mdat2.txt", package = "MicroDatosEs"), header = TRUE, sep = "\t", fileEncoding = "UTF-8", stringsAsFactors = FALSE) head(mdat2_example)
# This command reads a few lines sampled from # the EPA for 2011Q1 x <- test.metadata(system.file("extdata", "sampleEPA0111.txt", package = "MicroDatosEs"), system.file("metadata", "epa_mdat1.txt", package = "MicroDatosEs"), system.file("metadata", "epa_mdat2.txt", package = "MicroDatosEs")) # Example of first metadata file mdat1_example <- read.table(system.file("metadata", "epa_mdat1.txt", package = "MicroDatosEs"), header = TRUE, sep = "\t", fileEncoding = "UTF-8", stringsAsFactors = FALSE) head(mdat1_example) # Example of second metadata file mdat2_example <- read.table(system.file("metadata", "epa_mdat2.txt", package = "MicroDatosEs"), header = TRUE, sep = "\t", fileEncoding = "UTF-8", stringsAsFactors = FALSE) head(mdat2_example)