ESdata is an R package that allows access to statistical
information from Spain structured as ordered data (tidy data).
If you have previously installed the devtools package, you
can install the package from Github by doing:
devtools::install_github("jmsallan/ESdata")
Once the package is installed, we can access the data by doing:
library(ESdata)
The package allows access to a set of data structured in data
frames, with the only dependency on having a version of R equal or
higher than 3.5.0. A good alternative to explore this data
is to use the tidyverse packages:
library(tidyverse)
In its current version, the package has information related to:
In this document we will show the information available on the Gross Domestic Product (GDP).
The gross domestic product (GDP) is the monetary value of the final goods and services produced by an economy in a period of time. GDP measures the increase in wealth or wealth value of an economy in an aggregate manner. Its measurement allows to evaluate the growth of an economy, how an economy obtains and spends its income, and how it distributes it among its members from a macroeconomic point of view.
In contrast to other aggregates that measure the output of an economy, GDP is:
GDP is the preferred measure of national income evaluation, since it includes the goods available to the inhabitants of the territory (interior), without having to wait to take into account the depreciation of capital goods (gross).
Usually GDP is measured at market prices. This means that the price of the goods includes price increases due to taxes on goods (e.g. Value Added Tax) and decreases due to subsidies.
GDP, like the rest of national income aggregates, can be calculated in three ways:
The three approaches give the same value of GDP, and their analysis makes it possible to obtain additional information on the generation and distribution of income in a country.
The National Institute of Statistics (INE) provides quarterly GDP
values at market prices, as well as aggregates for their calculation
from the three approaches. The GDP data incorporated into
ESdata have been obtained from the tables at https://www.ine.es/dynt3/inebase/es/index.htm?padre=5614&capsel=5615.
The standardized methodological report can be found at https://www.ine.es/dynt3/metadatos/es/RespuestaDatos.html?oe=30024.
The following table shows the aggregates reported by the INE for the calculation of GDP through aggregate demand. This approach allows us to assess how it evolves:
| agr_label | agregado | nivel |
|---|---|---|
| pib | Producto interior bruto a precios de mercado | 1 |
| dn | Demanda nacional | 1 |
| xm | Demanda externa | 1 |
| C | Gasto en consumo final | 2 |
| C_h_isflsh | Gasto en consumo final de los hogares y las ISFLSH | 2 |
| C_h | Gasto en consumo final de los hogares | 2 |
| C_h_fi | Gasto en consumo final interior de los hogares | 2 |
| C_isflsh | Gasto en consumo final de las ISFLSH | 2 |
| C_AAPP | Gasto en consumo final de las AAPP | 2 |
| C_fie | Consumo final individual efectivo | 2 |
| FBC | Formación bruta de capital | 2 |
| X_bs | Exportaciones de bienes y servicios | 2 |
| M_bs | Importaciones de bienes y servicios | 2 |
| C_fi_bd | Gasto en consumo final interior de los hogares. Bienes duraderos | 3 |
| C_fi_obs | Gasto en consumo final interior de los hogares. Otros bienes y servicios | 3 |
| C_fi_AAPP | Gasto en consumo final individual de las AAPP | 3 |
| C_fc_AAPP | Gasto en consumo final colectivo de las AAPP | 3 |
| FBCF | Formación bruta de capital fijo (FBCF) | 3 |
| VE_OV | Variación de existencias y adquisiciones menos cesiones de objetos valiosos | 3 |
| VE | Variación de existencias | 3 |
| OV | Adquisiciones menos cesiones de objetos valiosos | 3 |
| X_b | Exportaciones de bienes | 3 |
| X_s | Exportaciones de servicios | 3 |
| M_b | Importaciones de bienes | 3 |
| M_s | Importaciones de servicios | 3 |
| FBCF_afm | FBCF. Activos fijos materiales | 4 |
| FBCF_afi | FBCF. Activos fijos inmateriales. Productos de la propiedad intelectual | 4 |
| X_rm | Exportaciones de servicios. Gasto de los hogares no residentes en el territorio económico | 4 |
| M_rm | Importaciones de servicios. Gasto de los hogares residentes en el resto del mundo | 4 |
| FBCF_afm_con | FBCF. Activos fijos materiales. Construcción | 5 |
| FBCF_afm_maq | FBCF. Activos fijos materiales. Maquinaria, bienes de equipo y sistemas de armamento | 5 |
| FBCF_afm_rbc | FBCF. Activos fijos materiales.Recursos biológicos cultivados | 5 |
| FBCF_afm_con_viv | FBCF. Activos fijos materiales. Construcción. Viviendas | 6 |
| FBCF_afm_con_edif | FBCF. Activos fijos materiales. Construcción. Otros edificios y construcciones | 6 |
| FBCF_afm_maq_transp | FBCF. Activos fijos materiales. Maquinaria, bienes de equipo y sistemas de armamento. Material de transporte | 6 |
| FBCF_afm_maq_arm | FBCF. Activos fijos materiales. Maquinaria, bienes de equipo y sistemas de armamento. Otros | 6 |
The following table shows the aggregates reported by the INE for the calculation of GDP through aggregate supply. This approach allows us to assess how various economic activities contribute to total output.
| agr_label | agregado | nivel |
|---|---|---|
| pib | Producto interior bruto a precios de mercado | 1 |
| vab_A | VABpb Agricultura, ganadería, silvicultura y pesca (A, CNAE 2009) | 1 |
| vab_BE | VABpb Industria (B-E, CNAE 2009) | 1 |
| vab_F | VABpb Construcción (F, CNAE 2009) | 1 |
| vab_GT | VABpb Servicios (G-T, CNAE 2009) | 1 |
| imp_sub | Impuestos menos subvenciones sobre los productos | 1 |
| vab_C | VABpb Industria. Industria manufacturera (C, CNAE 2009) | 2 |
| vab_GI | VABpb Servicios. Comercio, transporte y hostelería (G-I, CNAE 2009) | 2 |
| vab_J | VABpb Servicios. Información y comunicaciones (J, CNAE 2009) | 2 |
| vab_K | VABpb Servicios. Actividades financieras y de seguros (K, CNAE 2009) | 2 |
| vab_L | VABpb Servicios. Actividades inmobiliarias (L, CNAE 2009) | 2 |
| vab_MN | VABpb Servicios. Actividades profesionales, científicas y técnicas y otras (M-N, CNAE 2009) | 2 |
| vab_OQ | VABpb Servicios. Administración pública, educación y sanidad (O-Q, CNAE 2009) | 2 |
| vab_RT | VABpb Servicios. Actividades artísticas, recreativas y otros servicios (R-T, CNAE 2009) | 2 |
| imp | Impuestos sobre los productos | 2 |
| sub | Subvenciones sobre los productos | 2 |
The following table shows the aggregates reported by the INE for the calculation of GDP through income. This approach makes it possible to assess how income is distributed between labor (salaries) and capital (profits and rents).
| agr_label | agregado | nivel |
|---|---|---|
| pib | Producto interior bruto a precios de mercado | 1 |
| rem | Remuneración de los asalariados | 1 |
| rem_A | Remuneración de los asalariados. Agricultura, ganadería, silvicultura y pesca (A, CNAE 2009) | 1 |
| rem_BE | Remuneración de los asalariados. Industria (B-E, CNAE 2009) | 1 |
| rem_C | Remuneración de los asalariados. Industria manufacturera (C, CNAE 2009) | 1 |
| rem_F | Remuneración de los asalariados. Construcción (F, CNAE 2009) | 1 |
| rem_GT | Remuneración de los asalariados. Servicios (G-T, CNAE 2009) | 1 |
| rem_GI | Remuneración de los asalariados. Comercio, transporte y hostelería (G-I, CNAE 2009) | 1 |
| rem_J | Remuneración de los asalariados. Información y comunicaciones (J, CNAE 2009) | 1 |
| rem_K | Remuneración de los asalariados. Actividades financieras y de seguros (K, CNAE 2009) | 1 |
| rem_L | Remuneración de los asalariados. Actividades inmobiliarias (L, CNAE 2009) | 1 |
| rem_MN | Remuneración de los asalariados. Actividades profesionales, científicas y técnicas y otras (M-N, CNAE 2009) | 1 |
| rem_OQ | Remuneración de los asalariados. Administración pública, educación y sanidad (O-Q, CNAE 2009) | 1 |
| rem_RT | Remuneración de los asalariados. Actividades artísticas, recreativas y otros servicios (R-T, CNAE 2009) | 1 |
| ben | Excedente de explotación bruto y Renta mixta bruta | 1 |
| imp_sub | Impuestos menos subvenciones sobre la producción y las importaciones | 1 |
| sal | Sueldos y salarios | 2 |
| css | Cotizaciones sociales a cargo de los empleadores | 2 |
| sal_A | Sueldos y salarios. Agricultura, ganadería, silvicultura y pesca (A, CNAE 2009) | 2 |
| css_A | Cotizaciones sociales a cargo de los empleadores. Agricultura, ganadería, silvicultura y pesca (A, CNAE 2009) | 2 |
| sal_BE | Sueldos y salarios. Industria (B-E, CNAE 2009) | 2 |
| css_BE | Cotizaciones sociales a cargo de los empleadores. Industria (B-E, CNAE 2009) | 2 |
| sal_C | Sueldos y salarios. Industria manufacturera (C, CNAE 2009) | 2 |
| css_C | Cotizaciones sociales a cargo de los empleadores. Industria manufacturera (C, CNAE 2009) | 2 |
| sal_F | Sueldos y salarios. Construcción (F, CNAE 2009) | 2 |
| css_F | Cotizaciones sociales a cargo de los empleadores. Construcción (F, CNAE 2009) | 2 |
| sal_GT | Sueldos y salarios. Servicios (G-T, CNAE 2009) | 2 |
| css_GT | Cotizaciones sociales a cargo de los empleadores. Servicios (G-T, CNAE 2009) | 2 |
| sal_GI | Sueldos y salarios. Comercio, transporte y hostelería (G-I, CNAE 2009) | 2 |
| css_GI | Cotizaciones sociales a cargo de los empleadores. Comercio, transporte y hostelería (G-I, CNAE 2009) | 2 |
| sal_J | Sueldos y salarios. Información y comunicaciones (J, CNAE 2009) | 2 |
| css_J | Cotizaciones sociales a cargo de los empleadores. Información y comunicaciones (J, CNAE 2009) | 2 |
| sal_K | Sueldos y salarios. Actividades financieras y de seguros (K, CNAE 2009) | 2 |
| css_K | Cotizaciones sociales a cargo de los empleadores. Actividades financieras y de seguros (K, CNAE 2009) | 2 |
| sal_L | Sueldos y salarios. Actividades inmobiliarias (L, CNAE 2009) | 2 |
| css_L | Cotizaciones sociales a cargo de los empleadores. Actividades inmobiliarias (L, CNAE 2009) | 2 |
| sal_MN | Sueldos y salarios. Actividades profesionales, científicas y técnicas y otras (M-N, CNAE 2009) | 2 |
| css_MN | Cotizaciones sociales a cargo de los empleadores. Actividades profesionales, científicas y técnicas y otras (M-N, CNAE 2009) | 2 |
| sal_OQ | Sueldos y salarios. Administración pública, educación y sanidad (O-Q, CNAE 2009) | 2 |
| css_OQ | Cotizaciones sociales a cargo de los empleadores. Administración pública, educación y sanidad (O-Q, CNAE 2009) | 2 |
| sal_RT | Sueldos y salarios. Actividades artísticas, recreativas y otros servicios (R-T, CNAE 2009) | 2 |
| css_RT | Cotizaciones sociales a cargo de los empleadores. Actividades artísticas, recreativas y otros servicios (R-T, CNAE 2009) | 2 |
| imp | Impuestos sobre la producción y las importaciones | 2 |
| sub | Subvenciones sobre la producción y las importaciones | 2 |
The information on GDP in ESdata is presented in
separate tables for each of the GDP approaches. All three approaches
have a table for the aggregates that I have presented in the previous
section and another for the data:
| enfoque | agregados | datos |
|---|---|---|
| demanda |
pib_demanda_agregados
|
pib_pm_demanda
|
| oferta |
pib_oferta_agregados
|
pib_pm_oferta
|
| rentas |
pib_rentas_agregados
|
pib_pm_rentas
|
The variables of each of the data tables are:
| datos | periodo | agregado | ajuste | tipo | dato | valor |
|---|---|---|---|---|---|---|
pib_pm_demanda
|
✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
pib_pm_oferta
|
✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
pib_pm_rentas
|
✓ | ✓ | ✓ | ✓ | ✓ |
El contenido de las variables es:
periodo: el último día del trimestre del dato
correspondiente a la fila, en formato de fecha Date.agregado correspondiente a cada una de las
filas.ajuste de cada fila: ajustado para
datos ajustados a estacionalidad y calendario, o
no_ajustado.tipo de dato: o valor o `indice’.dato, que puede ser base, variación
trimestral var_trim, variación anual
var_anual, aportación trimestral ap_trim o
aportación anual ap_anual.valor, en índice o en millones de euros. Para el
enfoque de rentas no están disponibles datos en índice.The content of the variables is:
periodo: the last day of the quarter of the data
corresponding to the row, in date format Date.agregado: the aggregate corresponding to each of the
rows.ajuste: the adjustment of each row:
ajustado means adjusted for seasonality, and
no_ajustado not adjusted.tipo: the data type: either valor (actual
value) or indice (indexed value).dato: the data, which can be base value,
quarterly variation var_trim, annual variation
var_anual, quarterly contribution ap_trim or
annual contribution ap_anual.valor: the actual value, in index or in millions of
euros. For the income approach, index data are not available.A large number of visualizations and tables can be obtained with the data incorporated into the package. In each case it is necessary to do the previous filtering that allows us to obtain the required data. In this section we will present some examples of visualizations of GDP data.
In this graph we see the difference between unadjusted and adjusted GDP. We can see that to evaluate the evolution of GDP it is convenient to see the adjusted.
pib_pm_demanda %>%
filter(agregado == "pib" & tipo == "indice" & dato == "base") %>%
ggplot(aes(periodo, valor, group=ajuste)) +
geom_line(aes(linetype=ajuste)) +
scale_linetype_manual(values = c("solid", "dotted"), labels = c("ajustado", "no ajustado")) +
labs(title="Índice de PIB ajustado y no ajustado", x="", y="índice PIB") +
theme_bw() +
theme(legend.position = "bottom")
The graphic also shows how to use ggplot to
differentiate series by line type.
In this chart, we show the impact of COVID-19 on economic growth using annual and quarterly variations.
library(lubridate)
pib_pm_demanda %>%
filter(agregado == "pib" & ajuste == "ajustado" & tipo == "valor" & dato %in% c("var_anual", "var_trim")) %>%
filter(year(periodo) > 2017) %>%
mutate(valor = valor/100) %>%
ggplot(aes(periodo, valor, col=dato)) +
geom_point() +
geom_line() +
labs(title = "Impacto del COVID-19 en el IPC", x="", y="variación") +
scale_color_brewer(name = "variación", labels = c("anual", "trimestral"), palette = "PuOr") +
scale_y_continuous(labels = scales::percent) +
theme_dark() +
theme(legend.position = "bottom")
The graph shows the following resources:
year function of lubridate to
select data from 2017 onward.scale_y_continuous.theme_dark for screen presentations.With pib_pm_rentas we can evaluate how the income
distribution evolves. To do this we must take into account that GDP is
equal to remuneration of labor rem plus benefits
ben. Since we are evaluating GDP at market prices
pib, we must also add taxes and subsidies
imp_sub.
\[ \text{pib} = \text{rem} + \text{ben} + \text{imp_sub} \]
In the income aggregates, we see that remunerations include salaries
sal and company contributions to Social Security
css.
\[ \text{rem} = \text{sal} + \text{css} \]
We will use the first equation to find the weight of net wages, benefits, and indirect taxes in GDP at market prices:
pib_pm_rentas %>% filter(agregado %in% c("pib", "rem", "ben", "imp_sub") & dato == "base" & ajuste == "ajustado") %>%
pivot_wider(names_from = "agregado", values_from = "valor") %>%
mutate(pr_rem = rem/pib, pr_ben = ben/pib, pr_imp = imp_sub/pib) %>%
select(periodo, pr_rem, pr_ben, pr_imp) %>%
pivot_longer(cols = -periodo, names_to = "dato", values_to = "valor")
## # A tibble: 339 × 3
## periodo dato valor
## <date> <chr> <dbl>
## 1 2023-01-31 pr_rem 0.458
## 2 2023-01-31 pr_ben 0.438
## 3 2023-01-31 pr_imp 0.104
## 4 2022-12-31 pr_rem 0.463
## 5 2022-12-31 pr_ben 0.459
## 6 2022-12-31 pr_imp 0.0785
## 7 2022-09-30 pr_rem 0.471
## 8 2022-09-30 pr_ben 0.426
## 9 2022-09-30 pr_imp 0.103
## 10 2022-06-30 pr_rem 0.468
## # ℹ 329 more rows
Then we will make a graph with geom_area to see how the
variables evolve. The use of mutate is to change the order of the factor
levels of the variable value:
pib_pm_rentas %>%
filter(agregado %in% c("pib", "rem", "ben", "imp_sub") & dato == "base" & ajuste == "ajustado") %>%
pivot_wider(names_from = "agregado", values_from = "valor") %>%
mutate(pr_rem = rem/pib, pr_ben = ben/pib, pr_imp = imp_sub/pib) %>%
select(periodo, pr_rem, pr_ben, pr_imp) %>%
pivot_longer(cols = -periodo, names_to = "dato", values_to = "valor") %>%
mutate(dato = factor(dato, levels = c("pr_ben", "pr_rem", "pr_imp"))) %>%
ggplot(aes(periodo, valor, fill=dato)) +
geom_area() +
scale_fill_brewer(name = "rentas", labels = c("capital", "trabajo", "impuestos - subvenciones")) +
labs(title = "Reparto del PIB entre capital y trabajo", x="", y="") +
scale_y_continuous(labels = scales::percent) +
theme_bw() +
theme(legend.position = "bottom")
In this case, we have selected the colors using the default palette
of scale_fill_brewer.
The data pib_pm_oferta make it possible to evaluate the
weight in the economy of the different sectors of activity. In this
graph we see how the weight of the construction sector has evolved. We
put the data in context by reporting on the 2008 crocumentisis.
pib_pm_oferta %>%
filter(agregado %in% c("pib", "vab_F") & ajuste == "ajustado" & tipo == "valor" & dato == "base") %>%
pivot_wider(names_from = agregado, values_from = valor) %>%
mutate(prop = vab_F/pib) %>%
ggplot(aes(periodo, prop)) +
geom_line(size=1.2) +
labs(title="Peso de la construcción en la economía", y="construcción vs PIB", x="") +
geom_vline(xintercept = as.Date("2008-12-31"), linetype="dashed", size=0.5,col ="#FF0000") +
annotate("text", x=as.Date("2010-06-30"), y=0.12, label="crisis del 2008", hjust="left") +
annotate("curve", x=as.Date("2010-06-15"), y =0.12, xend=as.Date("2008-12-31"), yend=0.11, curvature=0.2, arrow = arrow(length = unit(2, "mm"))) +
scale_y_continuous(labels = scales::percent) +
theme_bw() +
theme(legend.position = "bottom")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Here we have again used the pivot_wider and
pivot_longer functions of tidyr to calculate
construction to GDP ratios.
Line graphs are used to evaluate the evolution of a quantity over time. The graph that we have presented shows the drop in the weight of construction after the 2008 crisis. To illustrate the absolute values of a magnitude, it is better to use a bar graph. Here we present the weight of construction in the economy, adding the GDP of the quarters of each year.
pib_pm_oferta %>%
filter(agregado %in% c("pib", "vab_F") & ajuste == "ajustado" & tipo == "valor" & dato == "base") %>%
pivot_wider(names_from = agregado, values_from = valor) %>%
mutate(year=year(periodo)) %>%
group_by(year) %>%
summarise(pib=sum(pib), constr=sum(vab_F)) %>%
mutate(prop = constr/pib) %>%
ggplot(aes(year, prop)) +
geom_bar(stat = "Identity", fill="#DC143C") +
labs(title="Peso de la construcción en la economía", y="construcción vs PIB", x="") +
scale_y_continuous(labels = scales::percent) +
theme_bw() +
theme(legend.position = "bottom")
We can also compare the weight of construction in GDP as a whole with bar graphs:
library(lubridate)
pib_pm_oferta %>%
filter(agregado %in% c("pib", "vab_F") & ajuste == "ajustado" & tipo == "valor" & dato == "base") %>%
pivot_wider(names_from = agregado, values_from = valor) %>%
mutate(year=year(periodo)) %>%
group_by(year) %>%
summarise(pib=sum(pib), constr=sum(vab_F)) %>%
pivot_longer(-year, values_to = "valor", names_to = "dato") %>%
ggplot(aes(year, valor, fill=dato)) +
geom_bar(stat = "Identity", position = "dodge") +
labs(title="Evolución del PIB y la construcción", y="millones euros", x="año") +
scale_fill_manual(name="Agregado", labels=c("VAB construcción", "Total PIB"), values = c("#B22222", "#228B22")) +
theme_bw() +
theme(legend.position = "bottom")
If you have any proposals or have detected any errors, you can make a pull request at: https://github.com/jmsallan/ESdata