This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(magrittr) | |
library(bench) | |
julia_weighted_atkinson_function <- JuliaCall::julia_eval("function weighted_atkinson(v, w, ϵ::Real, skipmissing::Bool) | |
if skipmissing | |
w = w[findall(!ismissing, v)] | |
v = v[findall(!ismissing, v)] | |
end | |
v = v/Statistics.mean(v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### Atkinson index ##### | |
""" | |
wtd_atkinson(v, w, ϵ) | |
Computes the weighted Atkinson index given an inequality adversion parameter ϵ. | |
""" | |
function wtd_atkinson(v::Array{<:Real,1}, w::Array{<:Real,1}, ϵ::Real)::Float64 | |
norm_mean!(v) | |
w = w/sum(w) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Benchmarking a call to 'Inequality.gini' without weights, | |
# and with a vector of 1s as weights. | |
using BenchmarkTools | |
using Inequality | |
v = rand(1:10000, 300) | |
w = repeat([1], 300) | |
@benchmark gini($v) evals=15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v <- c(8,5,1,3,5,6,7,6,3) # income | |
w <- seq(0.1, 0.9, 0.1) # weights | |
w <- w[order(v)] | |
v <- sort(v) | |
# compute πₖ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cppyy | |
import numpy as np | |
# 'translation' of the Python function below done by ChatGPT | |
cppyy.cppdef(""" | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <numeric> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Download the OECD detailed National Accounts | |
#' | |
#' @description | |
#' Uses the API to the OECD tables to download the National Accounts. | |
#' | |
#' Downloads all variables for all years for the selected countries. | |
#' | |
#' @details | |
#' The OECD API takes countries with ISO3. The function uses the METIS 'country' | |
#' table to convert ISO2 to ISO3. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rlang) | |
library(dplyr) | |
it14ih <- data.frame(hid = 1:6, | |
hi11 = c(3601, 13190, 0, 11479, 0, 4713), | |
hi13 = c(973, 0, 0, 478, 815, 399), | |
hi12 = c(0, 0, 0, 0, 0, 842), | |
hicapital = c(40, 41, 0, 100, 0, 83), | |
hpopwgt = c(567.1, 5308.3, 666.7, | |
692.2, 254.2, 632.6) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
national_accounts_df <- tibble::tibble(country = c("ITA", "ITA", "ITA", "ITA", "ITA"), | |
variable = c("NFD41R", "NFD11P", "NFB3GR", "NFD42R", "NFD45R"), | |
sector = c("S14", "S14", "S14", "S14", "S14"), | |
year = c("2016", "2016", "2016", "2016", "2016"), | |
value = c(27593.2, 84325810, 227852.9, 119509.5, 1034.7)) | |
estimates_from_microdata_df <- tibble::tibble(indicator = c("D11P", "B3GR+D41R+D42R+D45R"), | |
value = c(84328052, 894699.3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(haven) | |
#' Download the OECD detailed National Accounts | |
#' | |
#' @description | |
#' Uses the API to the OECD tables to download the National Accounts. | |
#' | |
#' Downloads all variables for all years for the selected countries. | |
#' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Summer workshop - Data preparation in R -------- | |
# COPY TO LISSY: ---------------------------------------------------------- | |
library(tidyverse) | |
library(magrittr) | |
# install.packages("Hmisc") |