Este documento analiza en detalle un dataset de Eurostat, ya elegido a partir de las tablas que genera EUROSTAT_TableDatasetGeneration.Rmd, y comprueba si cumple los requisitos para ser el dataset principal del proyecto personal de AEDV.

Para analizar otro dataset basta con cambiar su código en el chunk de abajo y volver a compilar.

# CÓDIGO DEL DATASET QUE VAMOS A ANALIZAR
dataset.name <- "demo_r_pjanaggr3"

1 Descarga, limpieza y guardado del dataset

Descargamos el dataset con la función get_eurostat y lo ordenamos por fechas y regiones.

# cargamos la tabla y la ordenamos por fechas y regiones
data <- get_eurostat(dataset.name, time_format = "date") |>
  as_tibble() |>
  arrange(TIME_PERIOD,geo)

Antes de guardar nada en disco, eliminamos las columnas que no aportan ninguna información: aquellas cuyo valor es siempre el mismo en todas las filas (por ejemplo, freq suele valer siempre A, porque el dataset ya viene fijado a una única frecuencia). Se excluyen de esta comprobación geo, TIME_PERIOD y values, que son las tres columnas estructurales del dataset (región, fecha y dato numérico), no dimensiones susceptibles de ser constantes sin más.

## Columnas con un solo valor (se eliminan):
##   - freq       = A
##   - unit       = NR

Guardamos el dataset lo primero de todo, nada más limpiarlo, en formato rds (el formato nativo de R: conserva los tipos de las columnas y ocupa mucho menos que un Excel).

filename <- dataset.name

saveRDS(data, file = paste0(filename, ".rds"))

cat("Fichero guardado:", paste0(filename, ".rds"),
    sprintf("(%.1f MB)\n", file.info(paste0(filename, ".rds"))$size / 1024^2))
## Fichero guardado: demo_r_pjanaggr3.rds (2.4 MB)

Guardamos también los metadatos del dataset recogidos en el catálogo de la asignatura (Eurostat.datasets.xlsx, generado por EUROSTAT_TableDatasetGeneration.Rmd): la fila correspondiente a este dataset, con las columnas pasadas a filas (Campo/Valor) para que quepan en una tabla estrecha.

# el catálogo habitual es el filtrado; si el dataset no está en él (el filtro
# deja fuera datasets que sí sirven) se busca en el volcado completo .raw
fila_metadatos <- openxlsx::read.xlsx("Eurostat.datasets.xlsx") |>
  filter(code == dataset.name)

if(nrow(fila_metadatos) == 0)
  fila_metadatos <- openxlsx::read.xlsx("Eurostat.datasets.raw.xlsx") |>
    filter(code == dataset.name)

if(nrow(fila_metadatos) == 0)
  stop("El dataset '", dataset.name, "' no aparece en el catálogo de Eurostat. ",
       "Comprueba el código o vuelve a generar los catálogos con EUROSTAT_TableDatasetGeneration.Rmd")

# el catálogo solo trae `topic` (nombre corto de la familia, para no cargar cada
# fila con miles de caracteres repetidos); aquí recuperamos la descripción
# completa desde Eurostat.topics.xlsx, para que quede en los metadatos del dataset
topics_tabla <- openxlsx::read.xlsx("Eurostat.topics.xlsx") |> as_tibble()
fila_metadatos <- fila_metadatos |>
  left_join(topics_tabla, by = "topic")

# pasamos las columnas a filas: son 26 campos, mucho más legibles en vertical
metadatos <- tibble(
  Campo = colnames(fila_metadatos),
  Valor = as.character(t(fila_metadatos))
)

openxlsx::write.xlsx(metadatos, file = paste0(filename, "_metadatos.xlsx"), overwrite = TRUE)

Una vez guardados en disco los metadatos (fichero xlsx) y los datos (fichero RDS), iniciamos el proceso de análisis. A partir de aquí el documento se compila solo con los ficheros ya guardados en disco (el rds y el xlsx de metadatos); no se usa ningún objeto de las secciones anteriores. Es a propósito: es la parte que se incorpora a la memoria del proyecto personal (ver la última sección, Incorporación del dataset a la memoria), así que tiene que poder ejecutarse sola (lo único que se usa de lo definido anteriormente es el dataset.name)

2 Análisis del dataset

metadatos

Campo Valor
code demo_r_pjanaggr3
title Population on 1 January by broad age group, sex and NUTS 3 region
topic POPULATION_DEMOGRAPHY_REGIONAL
Freq Y
N.periodos 36
Ini 1990
Fin 2025
N.observaciones 735652
N.regiones 2195
NUTS0 36
NUTS1 113
NUTS2 295
NUTS3 1338
AGREG 4
OTHERS 409
ESPAÑA TRUE
CANARIAS TRUE
N.atrib.combinados 15
Dimension_N.options unit 1 - sex 3 - age 5
ESMS https://ec.europa.eu/eurostat/cache/metadata/en/demo_r_gind3_esms.htm
last.update.of.data 28.08.2026
last.table.structure.change 10.08.2026
data.start 1990
data.end 2025
hierarchy 5

Descripción del topic al que pertenece el dataset

Each year Eurostat collects demographic data at regional level from EU, EFTA and Candidate countries as part of the Population Statistics data collection. POPSTAT is Eurostat’s main annual demographic data collection and aims to gather information on demography and migration at national and regional levels by various breakdowns (for the full overview see the Eurostat dedicated section). More specifically, POPSTAT collects data at regional levels on: population stocks; vital events (live births and deaths). Each country must send the statistics for the reference year (T) to Eurostat by 31 December of the following calendar year (T+1). Eurostat then publishes the data in March of the calendar year after that (T+2). Demographic data at regional level include statistics on the population at the end of the calendar year and on live births and deaths during that year, according to the official classification for statistics at regional level (NUTS - nomenclature of territorial units for statistics) in force in the year. These data are broken down by NUTS 2 and 3 levels for EU countries. For more information on the NUTS classification and its versions please refer to the Eurostat dedicated pages. For EFTA and Candidate countries the data are collected according to the agreed statistical regions that have been coded in a way that resembles NUTS. The breakdown of demographic data collected at regional level varies depending on the NUTS/statistical region level. These breakdowns are summarised below, along with the link to the corresponding online table: NUTS 2 level Population by sex, age and region of residence — demo_r_d2jan Population on 1 January by age group, sex and region of residence — demo_r_pjangroup Live births by mother’s age, mother’s year of birth and mother’s region of residence — demo_r_fagec Deaths by sex, age, and region of residence — demo_r_magec NUTS 3 level Population on 1 January by sex, age group and region of residence — demo_r_pjangrp3 Population on 1 January by broad age group, sex and region of residence — demo_r_pjanaggr3 Live births (total) by region of residence — demo_r_births Live births by five-year age group of the mothers and region of residence — demo_r_fagec3 Deaths (total) by region of residence — demo_r_deaths Deaths by five-year age group, sex and region of residence — demo_r_magec3 This more detailed breakdown (by five-year age group) of the data collected at NUTS 3 level started with the reference year 2013 and is in accordance with the European laws on demographic statistics. In addition to the regional codes set out in the NUTS classification in force, these online tables include few additional codes that are meant to cover data on persons and events that cannot be allocated to any official NUTS region. These codes are denoted as CCX/CCXX/CCXXX (Not regionalised/Unknown level 1/2/3; CC stands for country code) and are available only for France, Hungary, North Macedonia and Albania, reflecting the raw data as transmitted to Eurostat. For the reference years from 1990 to 2012 all countries sent to Eurostat all the data on a voluntary basis, therefore the completeness of the tables and the length of time series reflect the level of data received from the responsible National Statistical Institutes’ (NSIs) data provider. As a general remark, a lower data breakdown is available at NUTS 3 level as detailed: population data are broken down by sex and broad age groups (0-14, 15-64 and 65 or more). The data have this disaggregation since the reference year 2007 for all countries, and even longer for some — demo_r_pjanaggr3 vital events (live births and deaths) data are available only as totals, without any further breakdown — demo_r_births and demo_r_deaths Demographic indicators are calculated by Eurostat based on the above raw data using a common methodology for all countries and regions. The regional demographic indicators computed by NUTS level and the corresponding online tables are summarised below: NUTS 2 level Population structure indicators by region of residence (shares of various population age groups, dependency ratios and median age) — demo_r_pjanind2 Fertility indicators by region of residence — demo_r_find2 Fertility rates by age and region of residence — demo_r_frate2 Life table by age, sex and region of residence — demo_r_mlife Life expectancy by age, sex and region of residence — demo_r_mlifexp Infant mortality rates by region of residence — demo_r_minfind NUTS 3 level Population change - Demographic balance and crude rates at regional level — demo_r_gind3 Population density by region — demo_r_d3dens Population structure indicators by region of residence (shares of various population age groups, dependency ratios and median age) — demo_r_pjanind3 Fertility indicators by region of residence (total fertility rate, mean age of woman at childbirth and median age of woman at childbirth) — demo_r_find3 Notes: 1) All the indicators are computed for all lower NUTS regions included in the tables (e.g. data included in a table at NUTS 3 level will include also the data for NUTS 2, 1 and country levels). 2) Demographic indicators computed by NUTS 2 and 3 levels are calculated using input data that have different age breakdown. Therefore, minor differences can be noted between the values corresponding to the same indicator of the same region classified as NUTS 2, 1 or country level. 3) Since the reference year 2015, Eurostat has stopped collecting data on area; therefore, the table ‘Area by NUTS 3 region (demo_r_d3area)’ includes data up to the year 2015 included. 4) Starting with the reference year 2016, the population density indicator is computed using the new data on area ’Area by NUTS 3 region (reg_area3).

data

## # A tibble: 735,709 × 5
##   sex   age    geo   TIME_PERIOD  values
##   <chr> <chr>  <chr> <date>        <dbl>
## 1 T     TOTAL  AL    1990-01-01  3286500
## 2 T     TOTAL  AL0   1990-01-01  3286500
## 3 F     TOTAL  AT    1990-01-01  3989903
## 4 F     UNK    AT    1990-01-01        0
## 5 F     Y15-64 AT    1990-01-01  2589567
## # ℹ 735,704 more rows

2.1 Información sobre las columnas de la tabla descargada

Se presentan las diferentes dimensiones, cada una con sus valores posibles y el nº de observaciones.

COLUMNA: sex (3 opciones)

     sex N.Observ full_name
[1,] T   245247   Total    
[2,] F   245231   Females  
[3,] M   245231   Males    

COLUMNA: age (5 opciones)

     age    N.Observ full_name          
[1,] TOTAL  165915   Total              
[2,] UNK    145060   Unknown            
[3,] Y_GE65 141594   65 years or over   
[4,] Y15-64 141570   From 15 to 64 years
[5,] Y_LT15 141570   Less than 15 years 

CONTABILIZACIÓN Nº REGIONES NUTS A PARTIR DE LA COLUMNA geo (2195 opciones)

      NUTS      Number of Regions
 [1,] 0           36             
 [2,] 1          113             
 [3,] 2          295             
 [4,] 3         1338             
 [5,] EFTA         1             
 [6,] EU27_2007    1             
 [7,] EU27_2020    1             
 [8,] EU28         1             
 [9,] OTHERS     409             

COLUMNA: TIME_PERIOD (36 opciones)

      TIME_PERIOD N.observ
 [1,] 1990-01-01   4485   
 [2,] 1991-01-01   5432   
 [3,] 1992-01-01   6092   
 [4,] 1993-01-01   5354   
 [5,] 1994-01-01   5290   
 [6,] 1995-01-01   5594   
 [7,] 1996-01-01   5380   
 [8,] 1997-01-01   5383   
 [9,] 1998-01-01   5384   
[10,] 1999-01-01   5471   
[11,] 2000-01-01  13117   
[12,] 2001-01-01  16443   
[13,] 2002-01-01  19845   
[14,] 2003-01-01  20994   
[15,] 2004-01-01  20973   
[16,] 2005-01-01  21030   
[17,] 2006-01-01  25497   
[18,] 2007-01-01  26391   
[19,] 2008-01-01  27885   
[20,] 2009-01-01  27915   
[21,] 2010-01-01  28413   
[22,] 2011-01-01  28725   
[23,] 2012-01-01  29463   
[24,] 2013-01-01  23232   
[25,] 2014-01-01  30688   
[26,] 2015-01-01  31623   
[27,] 2016-01-01  31623   
[28,] 2017-01-01  31500   
[29,] 2018-01-01  31542   
[30,] 2019-01-01  31464   
[31,] 2020-01-01  27986   
[32,] 2021-01-01  27426   
[33,] 2022-01-01  27615   
[34,] 2023-01-01  27234   
[35,] 2024-01-01  26460   
[36,] 2025-01-01  26760   

Nº de observaciones en España/Canarias

## # A tibble: 10 × 3
##    geo   full_name     N.Observ
##    <chr> <chr>            <int>
##  1 ES    Spain              540
##  2 ES7   Canarias           540
##  3 ES70  Canarias           540
##  4 ES703 El Hierro          360
##  5 ES704 Fuerteventura      360
##  6 ES705 Gran Canaria       360
##  7 ES706 La Gomera          360
##  8 ES707 La Palma           360
##  9 ES708 Lanzarote          360
## 10 ES709 Tenerife           360

Combinaciones de atributos: cobertura por nivel NUTS y percentiles del tamaño de la serie temporal (nº de periodos por región).

sex age n_regiones NUTS0 NUTS1 NUTS2 NUTS3 P0 P25 P50 P75 P100
F TOTAL 2195 36 113 295 1338 1 23 25 31 36
M TOTAL 2195 36 113 295 1338 1 23 25 31 36
T TOTAL 2195 36 113 295 1338 1 23 25 31 36
F UNK 2195 36 113 295 1338 1 18 22 26 36
F Y15-64 2195 36 113 295 1338 1 18 19 26 36
F Y_GE65 2195 36 113 295 1338 1 18 19 26 36
F Y_LT15 2195 36 113 295 1338 1 18 19 26 36
M UNK 2195 36 113 295 1338 1 18 22 26 36
M Y15-64 2195 36 113 295 1338 1 18 19 26 36
M Y_GE65 2195 36 113 295 1338 1 18 19 26 36
M Y_LT15 2195 36 113 295 1338 1 18 19 26 36
T UNK 2195 36 113 295 1338 1 18 22 26 36
T Y15-64 2195 36 113 295 1338 1 18 19 26 36
T Y_GE65 2195 36 113 295 1338 1 18 19 26 36
T Y_LT15 2195 36 113 295 1338 1 18 19 26 36

2.2 Validación de requisitos AEDV

Atributos Cobertura geográfica Datos actualizados (≥ 2024) Tamaño series (P25 ≥ umbral) Tamaño series España/Canarias CUMPLE LOS 4
F / TOTAL ✔ ✔ ✔ ✔ ✔
M / TOTAL ✔ ✔ ✔ ✔ ✔
T / TOTAL ✔ ✔ ✔ ✔ ✔
F / UNK ✔ ✔ ✔ ✔ ✔
F / Y15-64 ✔ ✔ ✔ ✔ ✔
F / Y_GE65 ✔ ✔ ✔ ✔ ✔
F / Y_LT15 ✔ ✔ ✔ ✔ ✔
M / UNK ✔ ✔ ✔ ✔ ✔
M / Y15-64 ✔ ✔ ✔ ✔ ✔
M / Y_GE65 ✔ ✔ ✔ ✔ ✔
M / Y_LT15 ✔ ✔ ✔ ✔ ✔
T / UNK ✔ ✔ ✔ ✔ ✔
T / Y15-64 ✔ ✔ ✔ ✔ ✔
T / Y_GE65 ✔ ✔ ✔ ✔ ✔
T / Y_LT15 ✔ ✔ ✔ ✔ ✔

De las 15 combinaciones de atributos analizadas, 15 cumplen los cuatro criterios de validación (cobertura geográfica, datos actualizados, tamaño de las series temporales y tamaño de las series temporales en España/Canarias).

El requisito de disponer de al menos 4 atributos válidos se cumple ✓.

3 Incorporación del dataset a la memoria

Al compilar este documento se ha generado el fichero demo_r_pjanaggr3_analisis.Rmd: es la sección Análisis del dataset de arriba, preparada para la sección Comprensión de los datos de la memoria, con los títulos al nivel de esa sección. Para incorporar el dataset a la memoria:

  1. Copia a la carpeta de la memoria estos ficheros de la carpeta EUROSTAT: demo_r_pjanaggr3.rds, demo_r_pjanaggr3_metadatos.xlsx y demo_r_pjanaggr3_analisis.Rmd.
  2. Comprueba que en la carpeta de la memoria está también utilidades.R (viene en la carpeta ProyectoPersonal, junto al modelo de memoria) y que la memoria lo carga en el chunk de librerías: source("utilidades.R").
  3. Pega este chunk en la sección Comprensión de los datos de la memoria, cambiando los nombres de las tablas por otros que describan el dataset:
```{r, results='asis', cache=FALSE}
datos_demo_r_pjanaggr3 <- aedv_incluir_dataset("demo_r_pjanaggr3_analisis.Rmd")
```

Al compilar la memoria, el análisis aparece en el lugar del chunk y los datos quedan en la tabla datos_demo_r_pjanaggr3 (un tibble), con la que se sigue trabajando en el resto de la memoria. Si incorporas varios datasets, pega un chunk por cada uno, con nombres de tabla distintos. En un dataset auxiliar, que no tiene que cumplir los requisitos de AEDV, aedv_incluir_dataset("demo_r_pjanaggr3_analisis.Rmd", validacion = FALSE) omite la validación.

El texto explicativo del dataset (qué mide, qué significa cada variable y cada una de sus opciones…) se escribe en la memoria, antes o después del chunk, no en demo_r_pjanaggr3_analisis.Rmd: ese fichero se sustituye cada vez que se vuelve a generar.