README.md

presupuestoR

Español Este paquete proporciona una colección de funciones para el análisis presupuestario utilizando datos abiertos de Transparencia Presupuestaria.

English This package provides a collection of functions for budget analysis using open data from Transparency platform in Mexico.

Readme en español

Instalación

La versión en desarrollo puede ser instalada de GitHub con:

remotes::install_github("JavierMtzRdz/presupuestoR")
# Or
devtools::install_github("JavierMtzRdz/presupuestoR")   

Descripción general

Readme in English

Installation

You can install the development version of presupuestoR from GitHub with:

remotes::install_github("JavierMtzRdz/presupuestoR")
# Or
devtools::install_github("JavierMtzRdz/presupuestoR")   

Overview

Ejemplos / examples

sum_pef_tp() and id_ramo_to_abr_ramo()

This simple code estimates the approved budget for each ministry in 2022 and assign its abbreviation.

budget_ministery <- budget_2022 %>% 
  sum_pef_tp(id_ramo,
             keep_mensual = F) %>% 
  mutate(abr_ramo = id_ramo_to_abr_ramo(id_ramo),
         aprobado = aprobado/1000000) %>% 
  select(abr_ramo, aprobado)

budget_ministery
#> # A tibble: 48 × 2
#>    abr_ramo        aprobado
#>    <chr>              <dbl>
#>  1 P. Legislativo    15013.
#>  2 SE                 3587.
#>  3 SEP              364600.
#>  4 SSA              193948.
#>  5 Semar             37750.
#>  6 STPS              25384.
#>  7 Sedatu            12868.
#>  8 Semarnat          40796.
#>  9 Sener             47058.
#> 10 Aport. a la SS. 1092012.
#> # ℹ 38 more rows

deflactar_tp()

This code estimates the value of the approved budget in 2022 with 2010 prices in a few lines of code.

budget_ministery %>% 
  mutate(aprobado_2010_prices = 
           deflactar_tp(aprobado, 
                        2022,
                        2010))
#> # A tibble: 48 × 3
#>    abr_ramo        aprobado aprobado_2010_prices
#>    <chr>              <dbl>                <dbl>
#>  1 P. Legislativo    15013.                8560.
#>  2 SE                 3587.                2045.
#>  3 SEP              364600.              207902.
#>  4 SSA              193948.              110593.
#>  5 Semar             37750.               21526.
#>  6 STPS              25384.               14475.
#>  7 Sedatu            12868.                7338.
#>  8 Semarnat          40796.               23263.
#>  9 Sener             47058.               26833.
#> 10 Aport. a la SS. 1092012.              622685.
#> # ℹ 38 more rows

netear_tp() and negative_neteo_tp()

Here, the total net State spending for 2022 is estimated in three lines of code.

budget_2022 %>% 
  netear_tp() %>% 
  negative_neteo_tp() %>% 
  sum_pef_tp() %>% 
  transmute(comma(aprobado))
#> # A tibble: 1 × 1
#>   `comma(aprobado)`
#>   <chr>            
#> 1 7,088,250,300,000

indexing()

In this example, the GDP per capita for Oceania countries is indexed to the year 1952.

# Load the gapminder library
library(gapminder)

# Select Oceania countries from the gapminder dataset
oc_gapminder <- gapminder %>% 
  filter(continent == "Oceania") 

# Display the first few rows of the Oceania dataset
oc_gapminder %>% 
  arrange(year) %>% 
  head()
#> # A tibble: 6 × 6
#>   country     continent  year lifeExp      pop gdpPercap
#>   <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
#> 1 Australia   Oceania    1952    69.1  8691212    10040.
#> 2 New Zealand Oceania    1952    69.4  1994794    10557.
#> 3 Australia   Oceania    1957    70.3  9712569    10950.
#> 4 New Zealand Oceania    1957    70.3  2229407    12247.
#> 5 Australia   Oceania    1962    70.9 10794968    12217.
#> 6 New Zealand Oceania    1962    71.2  2488550    13176.

# Create a country-wise index based on GDP per capita for the year 1952
idx_gap <- oc_gapminder %>% 
  group_by(country) %>% 
  indexing(gdpPercap,
           year == 1952) 

# Display the first few rows of the indexed dataset
idx_gap %>% 
  arrange(year) %>% 
  head()
#> # A tibble: 6 × 7
#> # Groups:   country [2]
#>   country     continent  year lifeExp      pop gdpPercap index
#>   <fct>       <fct>     <int>   <dbl>    <int>     <dbl> <dbl>
#> 1 Australia   Oceania    1952    69.1  8691212    10040.  100 
#> 2 New Zealand Oceania    1952    69.4  1994794    10557.  100 
#> 3 Australia   Oceania    1957    70.3  9712569    10950.  109.
#> 4 New Zealand Oceania    1957    70.3  2229407    12247.  116.
#> 5 Australia   Oceania    1962    70.9 10794968    12217.  122.
#> 6 New Zealand Oceania    1962    71.2  2488550    13176.  125.

# Compare indexes across countries using a line plot
idx_gap %>% 
  ggplot(aes(x = year, 
             y = index,
             color = country)) +
  geom_line() 



JavierMtzRdz/presupuestoR documentation built on June 11, 2024, 11:38 a.m.