Análisis econométrico y visualización interactiva de indicadores de desarrollo económico global (PIB per cápita, esperanza de vida, convergencia intercontinental) y series monetarias y laborales oficiales de la Reserva Federal de los Estados Unidos (FRED).
Ninguna proyección financiera o presupuestaria opera aislada del ciclo macroeconómico. Este estudio demuestra cómo conectar RStudio directamente a los repositorios de la Reserva Federal (FRED) y paneles internacionales para examinar econométricamente el crecimiento del PIB per cápita, la dinámica del mercado laboral y la distribución global del ingreso.
El análisis estructural de indicadores del Banco Mundial (WDI), Curva de Preston y series macroeconómicas en RStudio fundamenta el diseño de premisas macroeconómicas en Presupuestos Maestros flexibles (con historial comprobado de 85% de mitigación inflacionaria y gestión multimoneda), así como el análisis multivariante de contagio intersectorial en el Estudio #17 (VAR(8), Johansen y Conectividad Diebold-Yilmaz, 2010–2026) y los escenarios de estrés del tablero Nexus Quant FP&A v3.0.
Ver Estudio #17: Econometría VAR(8) (2026) → | Nexus Quant FP&A v3.0 → | Consultoría Planificación Financiera
set.seed(42)
library(plotly)
library(gganimate)
library(ggplot2)
library(gapminder)
library(WDI)
library(sf)
library(rnaturalearth)
library(knitr)
library(kableExtra)
library(purrr)
library(dplyr)
library(quantmod)
library(leaflet)
# Paleta Corporativa Unificada (Curriculum.pdf — Executive Navy & Champagne Gold)
jbz_cv_palette <- c(
navy = "#0B1B33", plot_navy = "#102342", elev_navy = "#163259",
cobalt = "#1D4ED8", sky = "#38BDF8", gold = "#B8955A",
gold_soft = "#D9C29A", emerald = "#10B981", rose = "#F43F5E",
mist = "#C7D2E3", white = "#FFFFFF"
)
jbz_series_colors <- c("#38BDF8", "#B8955A", "#10B981", "#F43F5E", "#60A5FA", "#D9C29A", "#2DD4BF")
theme_jbz_cv <- function(base_size = 12) {
ggplot2::theme_minimal(base_size = base_size) +
ggplot2::theme(
plot.background = ggplot2::element_rect(fill = "#0B1B33", colour = NA),
panel.background = ggplot2::element_rect(fill = "#102342", colour = NA),
panel.grid.major = ggplot2::element_line(colour = "#1E3A5F", linewidth = 0.35),
panel.grid.minor = ggplot2::element_blank(),
text = ggplot2::element_text(colour = "#FFFFFF"),
axis.text = ggplot2::element_text(colour = "#C7D2E3"),
axis.title = ggplot2::element_text(colour = "#D9C29A", face = "bold"),
plot.title = ggplot2::element_text(colour = "#FFFFFF", face = "bold"),
plot.subtitle = ggplot2::element_text(colour = "#C7D2E3"),
legend.background = ggplot2::element_rect(fill = "#0B1B33", colour = NA),
legend.text = ggplot2::element_text(colour = "#FFFFFF")
)
}
jbz_plotly_cv <- function(p) {
plotly::layout(
p,
paper_bgcolor = "#0B1B33",
plot_bgcolor = "#102342",
font = list(color = "#FFFFFF", family = "Plus Jakarta Sans, Inter, sans-serif"),
xaxis = list(gridcolor = "rgba(199,210,227,0.14)", tickfont = list(color = "#C7D2E3")),
yaxis = list(gridcolor = "rgba(199,210,227,0.14)", tickfont = list(color = "#C7D2E3"))
)
}gdata <- gapminder[gapminder$year==2007, ]
g <- ggplot(gdata, aes(x=gdpPercap, y=lifeExp, label=country)) +
geom_point(aes(col=continent, size=pop/1e6)) +
geom_text_repel(size=2, box.padding = unit(0.5, "lines"), force=1,
segment.size = .1, segment.color = 'grey', max.iter = 100) +
scale_x_log10() +
theme_classic()
g
df <- gapminder
fig <- df %>%
plot_ly(
x = ~gdpPercap,
y = ~lifeExp,
size = ~pop,
color = ~continent,
frame = ~year,
text = ~country,
hoverinfo = "text",
type = 'scatter',
mode = 'markers'
)
fig <- fig %>% layout(
xaxis = list(
type = "log"
)
)
figggplotly(p <- ggplot(
gapminder,
aes(x = gdpPercap, y=lifeExp, size = pop, colour = country)
) +
geom_point(show.legend = FALSE, alpha = 0.7) +
scale_color_viridis_d() +
scale_size(range = c(2, 12)) +
scale_x_log10() +
labs(x = "PIB per Cápita", y = "Esperanza de vida",title = "Experanza de Vida y PIB per Cápita"))kable(aggregate(lifeExp ~ continent, gapminder, median), digits = 2, format = "html", row.names = TRUE) %>%
kable_styling(bootstrap_options = c("striped"),
full_width = T,
font_size = 15) %>%
scroll_box(height = "200px")| continent | lifeExp | |
|---|---|---|
| 1 | Africa | 47.79 |
| 2 | Americas | 67.05 |
| 3 | Asia | 61.79 |
| 4 | Europe | 72.24 |
| 5 | Oceania | 73.66 |
library("dplyr")
kable(gapminder %>%
filter(year == 2007) %>%
group_by(continent) %>%
summarise(lifeExp = median(lifeExp)), digits = 2, format = "html", row.names = TRUE) %>%
kable_styling(bootstrap_options = c("striped"),
full_width = T,
font_size = 15) %>%
scroll_box(height = "200px")| continent | lifeExp | |
|---|---|---|
| 1 | Africa | 52.93 |
| 2 | Americas | 72.90 |
| 3 | Asia | 72.40 |
| 4 | Europe | 78.61 |
| 5 | Oceania | 80.72 |
p <- ggplot(data = gapminder, aes(x = gdpPercap, y = lifeExp, color = continent))
ggplotly(p + geom_point() + geom_smooth(method = "loess") + scale_x_log10()+labs(
x = "PIB per Cápita",
y = "Experanza de Vida",
title = "Experanza de Vida y PIB per Cápita"
)) p <- ggplot(gapminder, aes(x = year, y = gdpPercap)) +
theme_jbz_cv()
jbz_plotly_cv(ggplotly(
p + geom_line(color = "#64748B", alpha = 0.55, aes(group = country)) +
geom_smooth(linewidth = 1.2, method = "loess", se = FALSE, color = "#B8955A") +
scale_y_log10(labels = scales::dollar) +
facet_wrap(~ continent) +
labs(title = "Trayectorias Globales del PIB per Cápita por Continente", x = "Año", y = "PIB per Cápita (USD)")
))jbz_plotly_cv(ggplotly(
ggplot(gapminder, aes(x = continent, y = lifeExp)) +
geom_boxplot(outlier.colour = "#F43F5E", fill = "#163259", color = "#38BDF8") +
geom_jitter(position = position_jitter(width = 0.1, height = 0), alpha = 0.25, color = "#D9C29A") +
theme_jbz_cv() +
labs(x = "Continentes", y = "Esperanza de Vida (Años)", title = "Distribución Global de Esperanza de Vida", caption = "Fuente: gapminder.")
))p <- ggplot(data = gapminder, aes(x = gdpPercap, y = lifeExp))
ggplotly(p + geom_point(alpha = 0.3) + geom_smooth(method = "gam") + scale_x_log10(labels = scales::dollar) + labs(
x = "PIB per capita", y = "Esperanza de Vida en Años", title = "Crecimiento Económico y Esperanza de Vida", subtitle = "Los puntos de datos son años-país", caption = "Fuente: gapminder."
))p <- ggplot(data = gapminder, aes(x = gdpPercap, y = lifeExp))
ggplotly(p + geom_point() + geom_smooth(method = "gam",formula=y ~ s(x, bs = "cs"))+labs(
x = "PIB per cápita", y = "Esperanza de Vida en Años", title = "Curva de Preston", caption = "Fuente: gapminder."
))##
## Call:
## lm(formula = lifeExp ~ log(gdpPercap) + pop + continent, data = gapminder)
##
## Residuals:
## Min 1Q Median 3Q Max
## -26.7090 -3.4832 0.4396 4.4062 18.6914
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.476e+00 1.352e+00 1.091 0.275
## log(gdpPercap) 6.524e+00 1.824e-01 35.778 < 2e-16 ***
## pop 9.990e-09 1.650e-09 6.056 1.72e-09 ***
## continentAmericas 6.729e+00 5.507e-01 12.218 < 2e-16 ***
## continentAsia 5.157e+00 4.880e-01 10.567 < 2e-16 ***
## continentEurope 9.290e+00 5.997e-01 15.491 < 2e-16 ***
## continentOceania 8.965e+00 1.521e+00 5.896 4.49e-09 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.965 on 1697 degrees of freedom
## Multiple R-squared: 0.7102, Adjusted R-squared: 0.7092
## F-statistic: 693.3 on 6 and 1697 DF, p-value: < 2.2e-16


out <- lm(lifeExp ~ log(gdpPercap) + log(pop) + continent, data = gapminder)
coefplot(out, sort = "magnitude", intercept = FALSE)
NY.GDP.PCAP.KN mediante WDI::WDI(country = "VE").
gapminder %>%
filter(year == 2007, country %in% c("Kenya", "Venezuela", "China")) %>%
select(country, continent) %>%
left_join(country_codes)## # A tibble: 3 x 4
## country continent iso_alpha iso_num
## <chr> <fct> <chr> <int>
## 1 China Asia CHN 156
## 2 Kenya Africa KEN 404
## 3 Venezuela Americas VEN 862
# Consulta moderna directa al Banco Mundial vía WDI::WDI (API oficial de indicadores del Banco Mundial)
Venezuela_GDPPC <- WDI::WDI(
country = "VE",
indicator = c("PIB Per Capita" = "NY.GDP.PCAP.KN"),
start = 1995,
end = 2023
) %>% dplyr::arrange(year)
tail(Venezuela_GDPPC, n = 10)## PIB Per Capita
## 1999-12-31 1666.183
## 2000-12-31 1695.293
## 2001-12-31 1720.546
## 2002-12-31 1539.820
## 2003-12-31 1395.319
## 2004-12-31 1622.226
## 2005-12-31 1760.096
## 2006-12-31 1903.768
## 2007-12-31 2040.218
## 2008-12-31 2117.724
## 2009-12-31 2021.009
## 2010-12-31 1962.294
## 2011-12-31 2012.515
## 2012-12-31 2091.416
## 2013-12-31 2089.537
## 2014-12-31 1990.680
## 2015-12-31 1864.555
## 2016-12-31 1559.042
## 2017-12-31 1335.106
## 2018-12-31 1092.476
# Descarga reproducible multiproposito de Indicadores de Desarrollo del Banco Mundial (WDI)
econIndicators <- c(
"PIB_Per_Capita" = "NY.GDP.PCAP.KN",
"Crecimiento_PIB_PC" = "NY.GDP.PCAP.KD.ZG",
"Tasa_Interes_Real" = "FR.INR.RINR",
"Tipo_Cambio_Real" = "PX.REX.REER",
"INPC" = "FP.CPI.TOTL.ZG",
"Fuerza_Laboral" = "SL.TLF.ACTI.ZS",
"Formacion_Capital" = "NE.GDI.TOTL.ZS",
"Importaciones_BS" = "NE.IMP.GNFS.ZS"
)
Venezuela_all_indicators <- WDI::WDI(
country = "VE",
indicator = econIndicators,
start = 2000,
end = 2023
) %>% dplyr::arrange(year)
tail(Venezuela_all_indicators, n = 6)## PIB Per Capita Crecimiento PIB Per Capita Tasa de Interés Real
## 2014-12-31 1990.680 -4.731050 -16.53998
## 2015-12-31 1864.555 -6.335766 -57.77085
## 2016-12-31 1559.042 -16.385328 -71.33319
## 2017-12-31 1335.106 -14.363688 -85.72509
## 2018-12-31 1092.476 -18.173106 NA
## 2019-12-31 NA NA NA
## Tipo de Cambio INPC Parte de la Fuerza Laboral. Rate
## 2014-12-31 128.9562 62.16865 66.675
## 2015-12-31 310.0486 121.73809 66.550
## 2016-12-31 740.6139 254.94853 65.949
## 2017-12-31 2321.5493 NA 65.346
## 2018-12-31 NA NA 64.499
## 2019-12-31 NA NA 64.301
## Formación Bruta de Capital Importación de Bienes y Servicios
## 2014-12-31 24.8102028 31.39699
## 2015-12-31 30.8684616 63.00163
## 2016-12-31 0.1023607 27.29002
## 2017-12-31 -3.7436802 36.43282
## 2018-12-31 NA NA
## 2019-12-31 NA NA
dygraph(Venezuela_all_indicators$`PIB Per Capita`, main = "PIB Per Capita en Venezuela (US $ a precios actuales)")%>%
dyRangeSelectordygraph(Venezuela_all_indicators$`Crecimiento PIB Per Capita`, main = "Crecimiento PIB Per Capita en Venezuela (% anual)")%>%
dyRangeSelectordygraph(Venezuela_all_indicators$`Tasa de Interés Real`, main = "Tasa de Interés Real en Venezuela (%)")%>%
dyRangeSelectordygraph(Venezuela_all_indicators$`Tipo de Cambio`, main = "Tipo de Cambio en Venezuela (VEF / US $)")%>%
dyRangeSelectordygraph(Venezuela_all_indicators$`INPC`, main = "INPC en Venezuela (2010 = 100)")%>%
dyRangeSelectordygraph(Venezuela_all_indicators$`Parte de la Fuerza Laboral. Rate`, main = "Parte de la Fuerza Laboral en Venezuela")%>%
dyRangeSelectordygraph(Venezuela_all_indicators$`Formación Bruta de Capital`, main = "Formación Bruta de Capital en Venezuela (% de crecimiento anual)")%>%
dyRangeSelectordygraph(Venezuela_all_indicators$`Importación de Bienes y Servicios`, main = "Importación de Bienes y Servicios en Venezuela (%) del PIB")%>%
dyRangeSelectorworld <- ne_countries(type = "countries", returnclass = 'sf')
tail(world[c('name', 'pop_est','gdp_md_est', 'economy','income_grp')], n = 10)## Simple feature collection with 10 features and 5 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -171.7911 ymin: -34.95265 xmax: 167.8449 ymax: 71.35776
## CRS: +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
## name pop_est gdp_md_est economy
## 167 Uruguay 3494382 43160.0 5. Emerging region: G20
## 168 United States 313973000 15094000.0 1. Developed region: G7
## 169 Uzbekistan 27606007 71670.0 6. Developing region
## 170 Venezuela 26814843 357400.0 5. Emerging region: G20
## 171 Vietnam 86967524 241700.0 5. Emerging region: G20
## 172 Vanuatu 218519 988.5 7. Least developed region
## 173 Yemen 23822783 55280.0 7. Least developed region
## 174 South Africa 49052489 491000.0 5. Emerging region: G20
## 175 Zambia 11862740 17500.0 7. Least developed region
## 176 Zimbabwe 12619600 9323.0 5. Emerging region: G20
## income_grp geometry
## 167 3. Upper middle income MULTIPOLYGON (((-57.62513 -...
## 168 1. High income: OECD MULTIPOLYGON (((-155.5421 1...
## 169 4. Lower middle income MULTIPOLYGON (((66.51861 37...
## 170 3. Upper middle income MULTIPOLYGON (((-71.33158 1...
## 171 4. Lower middle income MULTIPOLYGON (((108.0502 21...
## 172 4. Lower middle income MULTIPOLYGON (((167.8449 -1...
## 173 4. Lower middle income MULTIPOLYGON (((53.10857 16...
## 174 3. Upper middle income MULTIPOLYGON (((31.521 -29....
## 175 4. Lower middle income MULTIPOLYGON (((32.75938 -9...
## 176 5. Low income MULTIPOLYGON (((31.19141 -2...
popup <- paste0("<strong>Country: </strong>",
world$name,
"<br><strong>Market Stage: </strong>",
world$income_grp)# Mapa geoespacial moderno basado en Simple Features (sf + rnaturalearth) y Lienzo Oscuro Curriculum.pdf
world_sf <- rnaturalearth::ne_countries(scale = "medium", returnclass = "sf")
gdpPal <- leaflet::colorQuantile(palette = c("#102342", "#1D4ED8", "#38BDF8", "#B8955A", "#D9C29A"), domain = world_sf$gdp_md, n = 5)
leaf_world <- leaflet::leaflet(world_sf) %>%
leaflet::addProviderTiles("CartoDB.DarkMatter") %>%
leaflet::setView(lng = 20, lat = 15, zoom = 2) %>%
leaflet::addPolygons(
stroke = TRUE, weight = 0.6, color = "#B8955A",
smoothFactor = 0.2, fillOpacity = 0.78,
fillColor = ~gdpPal(gdp_md),
layerId = ~iso_a3, popup = ~paste0("<strong>", name, "</strong>")
)
leaf_world1. Automatización de Consultas a Bancos Centrales: El uso de quantmod y APIs públicas en R permite actualizar indicadores de inflación, tasas de interés, tipo de cambio y desempleo sin intervención manual.
2. Soporte para Escenarios Presupuestarios: La cuantificación rigurosa del ciclo macroeconómico fortalece las premisas analíticas de la planificación financiera corporativa para proyectar escenarios de ingresos y costos.
Excepto donde se indique lo contrario, el contenido de esta obra está bajo una licencia de Creative Commons Reconocimiento 4.0 Internacional.Jesús Benjamín Zerpa acompaña a juntas directivas, gerencias financieras y proyectos de inversión en la estructuración de presupuestos maestros, Implementación de Business Intelligence y modelos econométricos y predictivos en Python y R.