R/wdi_prepare.R

Defines functions prepare_country_series_summary prepare_wdi_db specify_used_series prepare_wdi_files make_wdi_files

prepare_country_series_summary = function() {
  setwd("D:/libraries/dataquiz/wdi")
  dat = readRDS("wdi_data.Rds")

  sum = dat %>%
    group_by(country_code, series_code) %>%
    summarize(
      num_obs = n(),
      num_distinct = n_distinct(value),
      first_year = min(year),
      last_year = max(year)
    )

  dbmisc::schema.template(sum, "country_series")

  schema.file = "D:/libraries/dataquiz/wdiquiz/inst/schemas/wdi.yaml"
  db.file = "D:/libraries/dataquiz/wdi/wdi.sqlite"
  db = dbmisc::dbConnectSQLiteWithSchema("wdi.sqlite",schema.file = schema.file)
  dbmisc::dbCreateSchemaTables(db,schema.file = schema.file,update = TRUE)

  dbInsert(db, "country_series", sum)


  series = read.csv("WDISeries.csv",stringsAsFactors = FALSE)
  cols = c("series_code", "topic", "indicator_name", "short_definition", "long_definition", "unit", "periodicity", "base_period", "other_notes", "aggregation_method", "limitations_and_exceptions", "notes_from_original_source", "general_comments", "source", "statistical_concept_and_methodology", "development_relevance", "related_source_links", "other_web_links", "related_indicators", "license_type", "x")
  colnames(series) = cols
  series = series[,1:16]

  dbInsert(db, "series", series)

  series.file = system.file("data/series.Rds",package="wdiquiz")
  series = readRDS(series.file)
  used = specify_used_series()
  series$used = series$indicator_name %in% used
  sum(series$used)
  saveRDS(series, series.file)

}


prepare_wdi_db = function() {
  library(vroom)
  library(dplyr)
  setwd("D:/libraries/dataquiz/wdi")

  series = read.csv("WDISeries.csv",stringsAsFactors = FALSE)

  inds = series$`Indicator.Name` %>% unique %>% na.omit()
  code = paste0('\t"',inds,'"', collapse=",\n")
  writeClipboard(code)

  df = tibble(inds)
  used = specify_used_series()
  code = paste0('"',colnames(series),'"', collapse=", ")
  code = gsub(".","_",code,fixed=TRUE) %>% tolower()
  cat(code)

  cols = c("series_code", "topic", "indicator_name", "short_definition", "long_definition", "unit", "periodicity", "base_period", "other_notes", "aggregation_method", "limitations_and_exceptions", "notes_from_original_source", "general_comments", "source", "statistical_concept_and_methodology", "development_relevance", "related_source_links", "other_web_links", "related_indicators", "license_type", "x")
  colnames(series) = cols
  series = series[,1:16]

  series = select(series, "series_code","topic","indicator_name")
  saveRDS(series,"series.Rds")

  library(dbmisc)
  schema.template(series, "series")
  schema.file = "D:/libraries/dataquiz/wdiquiz/inst/schemas/wdi.yaml"
  setwd("D:/libraries/dataquiz/wdi")
  dbCreateSQLiteFromSchema(schema.file,db.dir = getwd())

  db = dbmisc::dbConnectSQLiteWithSchema("wdi.sqlite",schema.file = schema.file)
  key = "EG.CFT.ACCS.ZS"
  dbGet(db,"select distinct country_code from data where series_code = :key",params = list(key=key))

  library(dbmisc)
  dbmisc::dbCreateSchemaTables(db,schema.file = schema.file)

  setwd("D:/libraries/dataquiz/wdi")
  #dat = readr::read_csv("WDIData.csv")
  #saveRDS(dat, "WDIData.Rds")
  dat = readRDS("WDIData.Rds")
  library(tidyr)
  dat = dat[, c(2,4,5:64)]
  ld = pivot_longer(dat,cols = 3:(NCOL(dat)),names_to = "year",values_to = "value")
  na.rows = which(is.na(ld$value))
  ld = ld[-na.rows,]
  colnames(ld)
  colnames(ld) = c("country_code", "series_code","year","value")
  ld$year = as.integer(ld$year)
  saveRDS(ld,"wdi_data.Rds")

  dbmisc::schema.template(ld, "data")

  colnames(ld)
  colnames(dat)

  #dbInsert(db, "data", ld)
  #dbInsert(db, "series", series)
}




specify_used_series = function() {
    use = c(
	"Fertilizer consumption (kilograms per hectare of arable land)",
	"Agricultural land (% of land area)",
	"Arable land (hectares per person)",
	"Arable land (% of land area)",
	"Permanent cropland (% of land area)",
	"Urban land area where elevation is below 5 meters (% of total land area)",
	"Land area where elevation is below 5 meters (% of total land area)",
	"Forest area (% of land area)",
	"Agricultural irrigated land (% of total agricultural land)",
	"Agricultural machinery, tractors per 100 sq. km of arable land",
	"Crop production index (2004-2006 = 100)",
	"Food production index (2004-2006 = 100)",
	"Livestock production index (2004-2006 = 100)",
	"Surface area (sq. km)",
	"Cereal yield (kg per hectare)",
	"Trade in services (% of GDP)",
	"Communications, computer, etc. (% of service imports, BoP)",
	"Transport services (% of service imports, BoP)",
	"Travel services (% of service imports, BoP)",
	"Foreign direct investment, net outflows (% of GDP)",
	"Current account balance (% of GDP)",
	"ICT service exports (% of service exports, BoP)",
	"Communications, computer, etc. (% of service exports, BoP)",
	"Insurance and financial services (% of service exports, BoP)",
	"Transport services (% of service exports, BoP)",
	"Travel services (% of service exports, BoP)",
	"Foreign direct investment, net inflows (% of GDP)",
	"S&P Global Equity Indices (annual % change)",
	"Market capitalization of listed domestic companies (current US$)",
	"Market capitalization of listed domestic companies (% of GDP)",
	"Listed domestic companies, total",
	"Stocks traded, total value (% of GDP)",
	"Net ODA provided, total (current US$)",
	"Net ODA provided, total (% of GNI)",
	"External debt stocks, total (DOD, current US$)",
	"External debt stocks (% of GNI)",
	"Short-term debt (% of total reserves)",
	"Short-term debt (% of exports of goods, services and primary income)",
	"Present value of external debt (% of GNI)",
	"Net official development assistance and official aid received (current US$)",
	"Net official development assistance and official aid received (constant 2016 US$)",
	"Net ODA received (% of GNI)",
	"Net ODA received per capita (current US$)",
	"Net ODA received (% of central government expense)",
	"Total debt service (% of GNI)",
	"Public and publicly guaranteed debt service (% of GNI)",
	"Public and publicly guaranteed debt service (% of exports of goods, services and primary income)",
	"Access to clean fuels and technologies for cooking (% of population)",
	"Energy intensity level of primary energy (MJ/$2011 PPP GDP)",
	"Access to electricity (% of population)",
	"Electricity production from coal sources (% of total)",
	"Electricity production from oil, gas and coal sources (% of total)",
	"Electricity production from hydroelectric sources (% of total)",
	"Electric power transmission and distribution losses (% of output)",
	"Electricity production from natural gas sources (% of total)",
	"Electricity production from nuclear sources (% of total)",
	"Electricity production from oil sources (% of total)",
	"Renewable electricity output (% of total electricity output)",
	"Electricity production from renewable sources, excluding hydroelectric (% of total)",
	"Renewable energy consumption (% of total final energy consumption)",
	"GDP per unit of energy use (PPP $ per kg of oil equivalent)",
	"GDP per unit of energy use (constant 2011 PPP $ per kg of oil equivalent)",
	"Energy imports, net (% of energy use)",
	"Alternative and nuclear energy (% of total energy use)",
	"Fossil fuel energy consumption (% of total)",
	"Energy use (kg of oil equivalent) per $1,000 GDP (constant 2011 PPP)",
	"Combustible renewables and waste (% of total energy)",
	"Electric power consumption (kWh per capita)",
	"Energy use (kg of oil equivalent per capita)",
	"CO2 intensity (kg per kg of oil equivalent energy use)",
	"CO2 emissions (kg per 2010 US$ of GDP)",
	"CO2 emissions (kt)",
	"CO2 emissions from liquid fuel consumption (% of total)",
	"CO2 emissions (metric tons per capita)",
	"CO2 emissions (kg per PPP $ of GDP)",
	"Other greenhouse gas emissions (% change from 1990)",
	"Total greenhouse gas emissions (% change from 1990)",
	"PM2.5 air pollution, mean annual exposure (micrograms per cubic meter)",
	"PM2.5 pollution, population exposed to levels exceeding WHO Interim Target-1 value (% of total)",
	"Bird species, threatened",
	"Droughts, floods, extreme temperatures (% of population, average 1990-2009)",
	"CO2 emissions from transport (% of total fuel combustion)",
	"Population density (people per sq. km of land area)",
	"Population living in areas where elevation is below 5 meters (% of total population)",
	"Population living in slums (% of urban population)",
	"Population in the largest city (% of urban population)",
	"Population in urban agglomerations of more than 1 million (% of total population)",
	"Pump price for diesel fuel (US$ per liter)",
	"Pump price for gasoline (US$ per liter)",
	"Annual freshwater withdrawals, total (% of internal resources)",
	"Terrestrial protected areas (% of total land area)",
	"Bank nonperforming loans to total gross loans (%)",
	"Bank capital to assets ratio (%)",
	"Commercial bank branches (per 100,000 adults)",
	"Borrowers from commercial banks (per 1,000 adults)",
	"Depositors with commercial banks (per 1,000 adults)",
	"Domestic credit to private sector by banks (% of GDP)",
	"Bank liquid reserves to bank assets ratio (%)",
	"Claims on central government (annual growth as % of broad money)",
	"Claims on other sectors of the domestic economy (annual growth as % of broad money)",
	"Claims on private sector (annual growth as % of broad money)",
	"Broad money (% of GDP)",
	"Consumer price index (2010 = 100)",
	"Inflation, consumer prices (annual %)",
	"Deposit interest rate (%)",
	"Lending interest rate (%)",
	"Real interest rate (%)",
	"Risk premium on lending (lending rate minus treasury bill rate, %)",
	"Claims on central government, etc. (% GDP)",
	"Claims on other sectors of the domestic economy (% of GDP)",
	"Domestic credit provided by financial sector (% of GDP)",
	"Domestic credit to private sector (% of GDP)",
	"Account ownership at a financial institution or with a mobile-money-service provider, poorest 40% (% of population ages 15+)",
	"Account ownership at a financial institution or with a mobile-money-service provider, richest 60% (% of population ages 15+)",
	"Research and development expenditure (% of GDP)",
	"Net acquisition of financial assets (% of GDP)",
	"Central government debt, total (% of GDP)",
	"Net lending (+) / net borrowing (-) (% of GDP)",
	"Revenue, excluding grants (% of GDP)",
	"Tax revenue (% of GDP)",
	"Taxes on income, profits and capital gains (% of total taxes)",
	"Human capital index (HCI) (scale 0-1)",
	"Average time to clear exports through customs (days)",
	"Time to obtain an electrical connection (days)",
	"Firms experiencing electrical outages (% of firms)",
	"Time to export, border compliance (hours)",
	"Time to export, documentary compliance (hours)",
	"Bribery incidence (% of firms experiencing at least one bribe payment request)",
	"Firms competing against unregistered firms (% of firms)",
	"Informal payments to public officials (% of firms)",
	"Losses due to theft and vandalism (% of annual sales for affected firms)",
	"Time required to obtain an operating license (days)",
	"Firms with female top manager (% of firms)",
	"Firms with female participation in ownership (% of firms)",
	"Firms that spend on R&D (% of firms)",
	"Firms experiencing losses due to theft and vandalism (% of firms)",
	"Firms offering formal training (% of firms)",
	"Time spent dealing with the requirements of government regulations (% of senior management time)",
	"Time to import, border compliance (hours)",
	"Time to import, documentary compliance (hours)",
	"Time to resolve insolvency (years)",
	"Time required to enforce a contract (days)",
	"Time required to register property (days)",
	"Cost of business start-up procedures (% of GNI per capita)",
	"Time required to start a business (days)",
	"Time to prepare and pay taxes (hours)",
	"Firms expected to give gifts in meetings with tax officials (% of firms)",
	"Labor tax and contributions (% of commercial profits)",
	"Total tax rate (% of commercial profits)",
	"Time required to build a warehouse (days)",
	"Scientific and technical journal articles",
	"Patent applications, residents",
	"Trademark applications, total",
	"Air transport, registered carrier departures worldwide",
	"Air transport, passengers carried",
	"Railways, goods transported (million ton-km)",
	"Railways, passengers carried (million passenger-km)",
	"Mobile cellular subscriptions (per 100 people)",
	"Fixed broadband subscriptions (per 100 people)",
	"Secure Internet servers (per 1 million people)",
	"Individuals using the Internet (% of population)",
	"Armed forces personnel, total",
	"Armed forces personnel (% of total labor force)",
	"Military expenditure (% of GDP)",
	"Military expenditure (% of general government expenditure)",
	"Arms exports (SIPRI trend indicator values)",
	"General government final consumption expenditure (annual % growth)",
	"General government final consumption expenditure (% of GDP)",
	"Household final consumption expenditure per capita (constant 2010 US$)",
	"Exports of goods and services (% of GDP)",
	"Gross fixed capital formation (% of GDP)",
	"Gross capital formation (% of GDP)",
	"Imports of goods and services (% of GDP)",
	"External balance on goods and services (% of GDP)",
	"Trade (% of GDP)",
	"Agriculture, value added per worker (constant 2010 US$)",
	"Agriculture, value added (% of GDP)",
	"Financial intermediary services indirectly Measured (FISIM) (current LCU)",
	"Industry, value added per worker (constant 2010 US$)",
	"Manufacturing, value added (% of GDP)",
	"Industry, value added (% of GDP)",
	"Chemicals (% of value added in manufacturing)",
	"Machinery and transport equipment (% of value added in manufacturing)",
	"Medium and high-tech industry (% manufacturing value added)",
	"Textiles and clothing (% of value added in manufacturing)",
	"Services, value added per worker (constant 2010 US$)",
	"Services, value added (% of GDP)",
	"Adjusted savings: education expenditure (% of GNI)",
	"Adjusted savings: carbon dioxide damage (% of GNI)",
	"Adjusted savings: net forest depletion (% of GNI)",
	"Adjusted savings: particulate emission damage (% of GNI)",
	"Adjusted savings: natural resources depletion (% of GNI)",
	"Adjusted savings: gross savings (% of GNI)",
	"Adjusted savings: net national savings (% of GNI)",
	"Adjusted net national income per capita (current US$)",
	"Adjusted net national income per capita (constant 2010 US$)",
	"Coal rents (% of GDP)",
	"Inflation, GDP deflator (annual %)",
	"GDP (current US$)",
	"GDP (constant 2010 US$)",
	"GDP growth (annual %)",
	"GDP, PPP (current international $)",
	"GDP, PPP (constant 2011 international $)",
	"GDP per capita (current US$)",
	"GDP per capita (constant 2010 US$)",
	"GDP per capita, PPP (current international $)",
	"GDP per capita, PPP (constant 2011 international $)",
	"Total natural resources rents (% of GDP)",
	"Gross domestic savings (% of GDP)",
	"GNI (current US$)",
	"GNI (constant 2010 US$)",
	"GNI, PPP (current international $)",
	"GNI, PPP (constant 2011 international $)",
	"GNI per capita (constant 2010 US$)",
	"GNI per capita, PPP (current international $)",
	"GNI per capita, PPP (constant 2011 international $)",
	"Coverage of social protection and labor programs (% of population)",
	"Coverage of unemployment benefits and ALMP (% of population)",
	"Benefit incidence of social safety net programs to poorest quintile (% of total safety net benefits)",
	"Coverage of social safety net programs (% of population)",
	"Coverage of social safety net programs in poorest quintile (% of population)",
	"Benefit incidence of social insurance programs to poorest quintile (% of total social insurance benefits)",
	"Coverage of social insurance programs (% of population)",
	"Coverage of social insurance programs in poorest quintile (% of population)",
	"Real effective exchange rate index (2010 = 100)",
	"Literacy rate, youth female (% of females ages 15-24)",
	"Literacy rate, youth total (% of people ages 15-24)",
	"Compulsory education, duration (years)",
	"Pupil-teacher ratio, primary",
	"School enrollment, primary (% gross)",
	"School enrollment, primary, female (% gross)",
	"School enrollment, primary, private (% of total primary)",
	"Persistence to grade 5, female (% of cohort)",
	"Persistence to grade 5, total (% of cohort)",
	"Persistence to last grade of primary, total (% of cohort)",
	"Primary education, teachers (% female)",
	"Lower secondary completion rate, female (% of relevant age group)",
	"Lower secondary completion rate, total (% of relevant age group)",
	"Secondary education, pupils (% female)",
	"Pupil-teacher ratio, secondary",
	"Secondary education, vocational pupils",
	"School enrollment, secondary (% gross)",
	"School enrollment, secondary, private (% of total secondary)",
	"Progression to secondary school, female (%)",
	"Progression to secondary school (%)",
	"Secondary education, teachers (% female)",
	"Pupil-teacher ratio, tertiary",
	"School enrollment, tertiary (% gross)",
	"School enrollment, tertiary, female (% gross)",
	"Tertiary education, academic staff (% female)",
	"Government expenditure per student, primary (% of GDP per capita)",
	"Expenditure on primary education (% of government expenditure on education)",
	"Government expenditure per student, secondary (% of GDP per capita)",
	"Expenditure on secondary education (% of government expenditure on education)",
	"Government expenditure per student, tertiary (% of GDP per capita)",
	"Expenditure on tertiary education (% of government expenditure on education)",
	"Government expenditure on education, total (% of government expenditure)",
	"Government expenditure on education, total (% of GDP)",
	"Women participating in the three decisions (own health care, major household purchases, and visiting family) (% of women age 15-49)",
	"Proportion of seats held by women in national parliaments (%)",
	"Proportion of time spent on unpaid domestic and care work, female (% of 24 hour day)",
	"Proportion of time spent on unpaid domestic and care work, male (% of 24 hour day)",
	"Proportion of women subjected to physical and/or sexual violence in the last 12 months (% of women age 15-49)",
	"Total alcohol consumption per capita (liters of pure alcohol, projected estimates, 15+ years of age)",
	"Probability of dying at age 5-14 years (per 1,000 children age 5)",
	"Women's share of population ages 15+ living with HIV (%)",
	"Prevalence of HIV, total (% of population ages 15-49)",
	"Mortality rate, under-5 (per 1,000 live births)",
	"Mortality rate, under-5, female (per 1,000 live births)",
	"Mortality rate, under-5, male (per 1,000 live births)",
	"Demand for family planning satisfied by modern methods (% of married women with demand for family planning)",
	"People using at least basic drinking water services (% of population)",
	"People using safely managed drinking water services (% of population)",
	"Children (0-14) living with HIV",
	"Antiretroviral therapy coverage (% of people living with HIV)",
	"Adults (ages 15+) and children (ages 0-14) newly infected with HIV",
	"Incidence of HIV (per 1,000 uninfected population ages 15-49)",
	"Hospital beds (per 1,000 people)",
	"Community health workers (per 1,000 people)",
	"Nurses and midwives (per 1,000 people)",
	"Physicians (per 1,000 people)",
	"Specialist surgical workforce (per 100,000 population)",
	"Incidence of malaria (per 1,000 population at risk)",
	"Use of insecticide-treated bed nets (% of under-5 population)",
	"Lifetime risk of maternal death (%)",
	"Smoking prevalence, total (ages 15+)",
	"Smoking prevalence, females (% of adults)",
	"Smoking prevalence, males (% of adults)",
	"Risk of catastrophic expenditure for surgical care (% of people at risk)",
	"Risk of impoverishing expenditure for surgical care (% of people at risk)",
	"Number of surgical procedures (per 100,000 population)",
	"Mortality rate attributed to household and ambient air pollution, age-standardized, female (per 100,000 female population)",
	"Mortality rate attributed to household and ambient air pollution, age-standardized, male (per 100,000 male population)",
	"Mortality rate attributed to household and ambient air pollution, age-standardized (per 100,000 population)",
	"Pregnant women receiving prenatal care (%)",
	"ARI treatment (% of children under 5 taken to a health provider)",
	"People using at least basic sanitation services, rural (% of rural population)",
	"People using at least basic sanitation services, urban (% of urban population)",
	"People using at least basic sanitation services (% of population)",
	"Exclusive breastfeeding (% of children under 6 months)",
	"Births attended by skilled health staff (% of total)",
	"Low-birthweight babies (% of births)",
	"Diabetes prevalence (% of population ages 20 to 79)",
	"Female genital mutilation prevalence (%)",
	"People with basic handwashing facilities including soap and water, rural (% of rural population)",
	"People with basic handwashing facilities including soap and water, urban (% of urban population)",
	"People with basic handwashing facilities including soap and water (% of population)",
	"Prevalence of underweight, weight for age, female (% of children under 5)",
	"Prevalence of underweight, weight for age, male (% of children under 5)",
	"Prevalence of underweight, weight for age (% of children under 5)",
	"Maternal mortality ratio (modeled estimate, per 100,000 live births)",
	"Maternal mortality ratio (national estimate, per 100,000 live births)",
	"People practicing open defecation, rural (% of rural population)",
	"People practicing open defecation, urban (% of urban population)",
	"People practicing open defecation (% of population)",
	"Diarrhea treatment (% of children under 5 receiving oral rehydration and continued feeding)",
	"Diarrhea treatment (% of children under 5 who received ORS packet)",
	"Prevalence of overweight, weight for height, female (% of children under 5)",
	"Prevalence of overweight, weight for height, male (% of children under 5)",
	"Prevalence of overweight, weight for height (% of children under 5)",
	"Mortality rate attributed to unintentional poisoning (per 100,000 population)",
	"Mortality rate attributed to unintentional poisoning, female (per 100,000 female population)",
	"Mortality rate attributed to unintentional poisoning, male (per 100,000 male population)",
	"People using safely managed sanitation services, rural (% of rural population)",
	"People using safely managed sanitation services, urban (% of urban population)",
	"People using safely managed sanitation services (% of population)",
	"Prevalence of stunting, height for age, female (% of children under 5)",
	"Prevalence of stunting, height for age, male (% of children under 5)",
	"Prevalence of stunting, height for age (% of children under 5)",
	"Suicide mortality rate, female (per 100,000 female population)",
	"Suicide mortality rate, male (per 100,000 male population)",
	"Suicide mortality rate (per 100,000 population)",
	"Mortality caused by road traffic injury (per 100,000 people)",
	"Mortality rate attributed to unsafe water, unsafe sanitation and lack of hygiene (per 100,000 population)",
	"Prevalence of wasting, weight for height, female (% of children under 5)",
	"Prevalence of wasting, weight for height, male (% of children under 5)",
	"Prevalence of wasting, weight for height (% of children under 5)",
	"Prevalence of severe wasting, weight for height, female (% of children under 5)",
	"Prevalence of severe wasting, weight for height, male (% of children under 5)",
	"Prevalence of severe wasting, weight for height (% of children under 5)",
	"Tuberculosis treatment success rate (% of new cases)",
	"Tuberculosis case detection rate (%, all forms)",
	"Incidence of tuberculosis (per 100,000 people)",
	"Increase in poverty gap at $1.90 ($ 2011 PPP) poverty line due to out-of-pocket health care expenditure (USD)",
	"Number of people pushed below the $1.90 ($ 2011 PPP) poverty line by out-of-pocket health care expenditure",
	"Increase in poverty gap at $1.90 ($ 2011 PPP) poverty line due to out-of-pocket health care expenditure (% of poverty line)",
	"Proportion of population pushed below the $1.90 ($ 2011 PPP) poverty line by out-of-pocket health care expenditure (%)",
	"Increase in poverty gap at $3.20 ($ 2011 PPP) poverty line due to out-of-pocket health care expenditure (USD)",
	"Number of people pushed below the $3.20 ($ 2011 PPP) poverty line by out-of-pocket health care expenditure",
	"Increase in poverty gap at $3.20 ($ 2011 PPP) poverty line due to out-of-pocket health care expenditure (% of poverty line)",
	"Proportion of population pushed below the $3.20 ($ 2011 PPP) poverty line by out-of-pocket health care expenditure (%)",
	"Number of people spending more than 10% of household consumption or income on out-of-pocket health care expenditure",
	"Proportion of population spending more than 10% of household consumption or income on out-of-pocket health care expenditure (%)",
	"Number of people spending more than 25% of household consumption or income on out-of-pocket health care expenditure",
	"Proportion of population spending more than 25% of household consumption or income on out-of-pocket health care expenditure (%)",
	"UHC service coverage index",
	"Newborns protected against tetanus (%)",
	"Current health expenditure (% of GDP)",
	"Current health expenditure per capita (current US$)",
	"Current health expenditure per capita, PPP (current international $)",
	"External health expenditure (% of current health expenditure)",
	"External health expenditure per capita (current US$)",
	"External health expenditure per capita, PPP (current international $)",
	"Domestic general government health expenditure (% of current health expenditure)",
	"Domestic general government health expenditure (% of GDP)",
	"Domestic general government health expenditure (% of general government expenditure)",
	"Domestic general government health expenditure per capita (current US$)",
	"Domestic general government health expenditure per capita, PPP (current international $)",
	"Out-of-pocket expenditure (% of current health expenditure)",
	"Out-of-pocket expenditure per capita (current US$)",
	"Out-of-pocket expenditure per capita, PPP (current international $)",
	"Domestic private health expenditure (% of current health expenditure)",
	"Domestic private health expenditure per capita (current US$)",
	"Domestic private health expenditure per capita, PPP  (current international $)",
	"Income share held by second 20%",
	"Income share held by third 20%",
	"Income share held by fourth 20%",
	"Income share held by highest 20%",
	"Income share held by highest 10%",
	"Income share held by lowest 10%",
	"Income share held by lowest 20%",
	"Poverty headcount ratio at $1.90 a day (2011 PPP) (% of population)",
	"Poverty gap at $1.90 a day (2011 PPP) (%)",
	"GINI index (World Bank estimate)",
	"Poverty headcount ratio at $3.20 a day (2011 PPP) (% of population)",
	"Poverty gap at $3.20 a day (2011 PPP) (%)",
	"Poverty gap at national poverty lines (%)",
	"Poverty headcount ratio at national poverty lines (% of population)",
	"Rural poverty gap at national poverty lines (%)",
	"Rural poverty headcount ratio at national poverty lines (% of rural population)",
	"Poverty headcount ratio at $5.50 a day (2011 PPP) (% of population)",
	"Poverty gap at $5.50 a day (2011 PPP) (%)",
	"Urban poverty gap at national poverty lines (%)",
	"Urban poverty headcount ratio at national poverty lines (% of urban population)",
	"Average transaction cost of sending remittances to a specific country (%)",
	"Average transaction cost of sending remittances from a specific country (%)",
	"Survey mean consumption or income per capita, bottom 40% of population (2011 PPP $ per day)",
	"Annualized average growth rate in per capita real survey mean consumption or income, bottom 40% of population (%)",
	"Survey mean consumption or income per capita, total population (2011 PPP $ per day)",
	"Annualized average growth rate in per capita real survey mean consumption or income, total population (%)",
	"Child employment in agriculture, female (% of female economically active children ages 7-14)",
	"Child employment in agriculture, male (% of male economically active children ages 7-14)",
	"Child employment in agriculture (% of economically active children ages 7-14)",
	"Employment in agriculture, female (% of female employment) (modeled ILO estimate)",
	"Employment in agriculture, male (% of male employment) (modeled ILO estimate)",
	"Employment in agriculture (% of total employment) (modeled ILO estimate)",
	#"Employment to population ratio, ages 15-24, female (%) (national estimate)",
	#"Employment to population ratio, ages 15-24, female (%) (modeled ILO estimate)",
	#"Employment to population ratio, ages 15-24, male (%) (national estimate)",
	#"Employment to population ratio, ages 15-24, male (%) (modeled ILO estimate)",
	#"Employment to population ratio, ages 15-24, total (%) (national estimate)",
	"Employment to population ratio, ages 15-24, total (%) (modeled ILO estimate)",
	"Employers, female (% of female employment) (modeled ILO estimate)",
	"Employers, male (% of male employment) (modeled ILO estimate)",
	"Employers, total (% of total employment) (modeled ILO estimate)",
	"Self-employed, female (% of female employment) (modeled ILO estimate)",
	"Self-employed, male (% of male employment) (modeled ILO estimate)",
	"Self-employed, total (% of total employment) (modeled ILO estimate)",
	"Female share of employment in senior and middle management (%)",
	#"Employment to population ratio, 15+, female (%) (national estimate)",
	"Employment to population ratio, 15+, female (%) (modeled ILO estimate)",
	#"Employment to population ratio, 15+, male (%) (national estimate)",
	"Employment to population ratio, 15+, male (%) (modeled ILO estimate)",
	#"Employment to population ratio, 15+, total (%) (national estimate)",
	"Employment to population ratio, 15+, total (%) (modeled ILO estimate)",
	"Vulnerable employment, female (% of female employment) (modeled ILO estimate)",
	"Vulnerable employment, male (% of male employment) (modeled ILO estimate)",
	"Vulnerable employment, total (% of total employment) (modeled ILO estimate)",
	"Wage and salaried workers, female (% of female employment) (modeled ILO estimate)",
	"Wage and salaried workers, male (% of male employment) (modeled ILO estimate)",
	"Wage and salaried workers, total (% of total employment) (modeled ILO estimate)",
	"Children in employment, unpaid family workers, female (% of female children in employment, ages 7-14)",
	"Children in employment, unpaid family workers, male (% of male children in employment, ages 7-14)",
	"Children in employment, unpaid family workers (% of children in employment, ages 7-14)",
	"Contributing family workers, female (% of female employment) (modeled ILO estimate)",
	"Contributing family workers, male (% of male employment) (modeled ILO estimate)",
	"Contributing family workers, total (% of total employment) (modeled ILO estimate)",
	"GDP per person employed (constant 2011 PPP $)",
	"Employment in industry, female (% of female employment) (modeled ILO estimate)",
	"Employment in industry, male (% of male employment) (modeled ILO estimate)",
	"Employment in industry (% of total employment) (modeled ILO estimate)",
	"Informal employment, female (% of total non-agricultural employment)",
	"Informal employment, male (% of total non-agricultural employment)",
	"Informal employment (% of total non-agricultural employment)",
	"Child employment in manufacturing, female (% of female economically active children ages 7-14)",
	"Child employment in manufacturing, male (% of male economically active children ages 7-14)",
	"Child employment in manufacturing (% of economically active children ages 7-14)",
	"Children in employment, self-employed, female (% of female children in employment, ages 7-14)",
	"Children in employment, self-employed, male (% of male children in employment, ages 7-14)",
	"Children in employment, self-employed (% of children in employment, ages 7-14)",
	"Child employment in services, female (% of female economically active children ages 7-14)",
	"Child employment in services, male (% of male economically active children ages 7-14)",
	"Child employment in services (% of economically active children ages 7-14)",
	"Employment in services, female (% of female employment) (modeled ILO estimate)",
	"Employment in services, male (% of male employment) (modeled ILO estimate)",
	"Employment in services (% of total employment) (modeled ILO estimate)",
	"Children in employment, female (% of female children ages 7-14)",
	"Children in employment, male (% of male children ages 7-14)",
	"Average working hours of children, study and work, female, ages 7-14 (hours per week)",
	"Children in employment, study and work, female (% of female children in employment, ages 7-14)",
	"Average working hours of children, study and work, male, ages 7-14 (hours per week)",
	"Children in employment, study and work, male (% of male children in employment, ages 7-14)",
	"Average working hours of children, study and work, ages 7-14 (hours per week)",
	"Children in employment, study and work (% of children in employment, ages 7-14)",
	"Average working hours of children, working only, female, ages 7-14 (hours per week)",
	"Children in employment, work only, female (% of female children in employment, ages 7-14)",
	"Average working hours of children, working only, male, ages 7-14 (hours per week)",
	"Children in employment, work only, male (% of male children in employment, ages 7-14)",
	"Average working hours of children, working only, ages 7-14 (hours per week)",
	"Children in employment, work only (% of children in employment, ages 7-14)",
	"Children in employment, total (% of children ages 7-14)",
	"Labor force participation rate for ages 15-24, female (%) (national estimate)",
	"Labor force participation rate for ages 15-24, female (%) (modeled ILO estimate)",
	"Labor force participation rate for ages 15-24, male (%) (national estimate)",
	"Labor force participation rate for ages 15-24, male (%) (modeled ILO estimate)",
	"Labor force participation rate for ages 15-24, total (%) (national estimate)",
	"Labor force participation rate for ages 15-24, total (%) (modeled ILO estimate)",
	"Labor force participation rate, female (% of female population ages 15-64) (modeled ILO estimate)",
	"Labor force participation rate, male (% of male population ages 15-64) (modeled ILO estimate)",
	"Labor force participation rate, total (% of total population ages 15-64) (modeled ILO estimate)",
	"Labor force with advanced education, female (% of female working-age population with advanced education)",
	"Labor force with advanced education, male (% of male working-age population with advanced education)",
	"Labor force with advanced education (% of total working-age population with advanced education)",
	"Labor force with basic education, female (% of female working-age population with basic education)",
	"Labor force with basic education, male (% of male working-age population with basic education)",
	"Labor force with basic education (% of total working-age population with basic education)",
	"Labor force participation rate, female (% of female population ages 15+) (national estimate)",
	"Labor force participation rate, female (% of female population ages 15+) (modeled ILO estimate)",
	"Ratio of female to male labor force participation rate (%) (national estimate)",
	"Ratio of female to male labor force participation rate (%) (modeled ILO estimate)",
	"Labor force participation rate, male (% of male population ages 15+) (national estimate)",
	"Labor force participation rate, male (% of male population ages 15+) (modeled ILO estimate)",
	"Labor force participation rate, total (% of total population ages 15+) (national estimate)",
	"Labor force participation rate, total (% of total population ages 15+) (modeled ILO estimate)",
	"Labor force with intermediate education, female (% of female working-age population with intermediate education)",
	"Labor force with intermediate education, male (% of male working-age population with intermediate education)",
	"Labor force with intermediate education (% of total working-age population with intermediate education)",
	"Part time employment, female (% of total female employment)",
	"Part time employment, male (% of total male employment)",
	"Part time employment, total (% of total employment)",
	"Labor force, female (% of total labor force)",
	"Labor force, total",
	"Unemployment, youth female (% of female labor force ages 15-24) (national estimate)",
	"Unemployment, youth female (% of female labor force ages 15-24) (modeled ILO estimate)",
	"Unemployment, youth male (% of male labor force ages 15-24) (national estimate)",
	"Unemployment, youth male (% of male labor force ages 15-24) (modeled ILO estimate)",
	"Unemployment, youth total (% of total labor force ages 15-24) (national estimate)",
	"Unemployment, youth total (% of total labor force ages 15-24) (modeled ILO estimate)",
	"Unemployment with advanced education, female (% of female labor force with advanced education)",
	"Unemployment with advanced education, male (% of male labor force with advanced education)",
	"Unemployment with advanced education (% of total labor force with advanced education)",
	"Unemployment with basic education, female (% of female labor force with basic education)",
	"Unemployment with basic education, male (% of male labor force with basic education)",
	"Unemployment with basic education (% of total labor force with basic education)",
	"Unemployment with intermediate education, female (% of female labor force with intermediate education)",
	"Unemployment with intermediate education, male (% of male labor force with intermediate education)",
	"Unemployment with intermediate education (% of total labor force with intermediate education)",
	"Share of youth not in education, employment or training, female (% of female youth population)",
	"Share of youth not in education, employment or training, male (% of male youth population)",
	"Share of youth not in education, employment or training, total (% of youth population)",
	"Unemployment, female (% of female labor force) (national estimate)",
	"Unemployment, female (% of female labor force) (modeled ILO estimate)",
	"Unemployment, male (% of male labor force) (national estimate)",
	"Unemployment, male (% of male labor force) (modeled ILO estimate)",
	"Unemployment, total (% of total labor force) (national estimate)",
	"Unemployment, total (% of total labor force) (modeled ILO estimate)",
	"Children in employment, wage workers, female (% of female children in employment, ages 7-14)",
	"Children in employment, wage workers, male (% of male children in employment, ages 7-14)",
	"Children in employment, wage workers (% of children in employment, ages 7-14)",
	"Net migration",
	"Refugee population by country or territory of asylum",
	"Refugee population by country or territory of origin",
	"International migrant stock, total",
	"International migrant stock (% of population)",
	"Prevalence of undernourishment (% of population)",
	"Consumption of iodized salt (% of households)",
	"Vitamin A supplementation coverage rate (% of children ages 6-59 months)",
	"Adolescent fertility rate (births per 1,000 women ages 15-19)",
	"Mortality rate, adult, female (per 1,000 female adults)",
	"Mortality rate, adult, male (per 1,000 male adults)",
	"Birth rate, crude (per 1,000 people)",
	"Death rate, crude (per 1,000 people)",
	"Contraceptive prevalence, modern methods (% of women ages 15-49)",
	"Contraceptive prevalence, any methods (% of women ages 15-49)",
	"Mortality rate, infant, female (per 1,000 live births)",
	"Mortality rate, infant (per 1,000 live births)",
	"Mortality rate, infant, male (per 1,000 live births)",
	"Life expectancy at birth, female (years)",
	"Life expectancy at birth, total (years)",
	"Life expectancy at birth, male (years)",
	"Fertility rate, total (births per woman)",
	"Survival to age 65, female (% of cohort)",
	"Survival to age 65, male (% of cohort)",
	"Wanted fertility rate (births per woman)",
	"Female headed households (% of households with a female head)",
	"Women who were first married by age 15 (% of women ages 20-24)",
	"Women who were first married by age 18 (% of women ages 20-24)",
	"Teenage mothers (% of women ages 15-19 who have had children or are currently pregnant)",
	"Population ages 0-14 (% of total population)",
	"Population ages 15-64 (% of total population)",
	"Population ages 65 and above (% of total population)",
	"Sex ratio at birth (male births per female births)",
	"Age dependency ratio (% of working-age population)",
	"Age dependency ratio, old (% of working-age population)",
	"Age dependency ratio, young (% of working-age population)",
	"Population growth (annual %)",
	"Researchers in R&D (per million people)",
	"Technicians in R&D (per million people)",
	"Population, total",
	"Population, female (% of total population)",
	"Population, male (% of total population)",
	"Completeness of death registration with cause-of-death information (%)",
	"Rural population (% of total population)",
	"Urban population (% of total population)",
	"Unmet need for contraception (% of married women ages 15-49)",
	"International tourism, number of arrivals",
	"International tourism, number of departures",
	"International tourism, receipts (current US$)",
	"International tourism, receipts (% of total exports)",
	"International tourism, expenditures (% of total imports)",
	"Merchandise trade (% of GDP)",
	"Import volume index (2000 = 100)",
	"Binding coverage, manufactured products (%)",
#	"Bound rate, simple mean, manufactured products (%)",
	"Share of tariff lines with international peaks, manufactured products (%)",
	"Tariff rate, applied, simple mean, manufactured products (%)",
	"Tariff rate, most favored nation, simple mean, manufactured products (%)",
	#"Share of tariff lines with specific rates, manufactured products (%)",
	"Tariff rate, applied, weighted mean, manufactured products (%)",
	"Tariff rate, most favored nation, weighted mean, manufactured products (%)",
	"Binding coverage, all products (%)",
	#"Bound rate, simple mean, all products (%)",
	"Share of tariff lines with international peaks, all products (%)",
	"Tariff rate, applied, simple mean, all products (%)",
	"Tariff rate, most favored nation, simple mean, all products (%)",
	"Share of tariff lines with specific rates, all products (%)",
	"Tariff rate, applied, weighted mean, all products (%)",
	"Tariff rate, most favored nation, weighted mean, all products (%)",
	"Binding coverage, primary products (%)",
	"Bound rate, simple mean, primary products (%)",
	"Share of tariff lines with international peaks, primary products (%)",
	"Tariff rate, applied, simple mean, primary products (%)",
	"Tariff rate, most favored nation, simple mean, primary products (%)",
	"Share of tariff lines with specific rates, primary products (%)",
	"Tariff rate, applied, weighted mean, primary products (%)",
	"Tariff rate, most favored nation, weighted mean, primary products (%)",
	"Import unit value index (2000 = 100)",
	"Agricultural raw materials imports (% of merchandise imports)",
	"Food imports (% of merchandise imports)",
	"Fuel imports (% of merchandise imports)",
	"ICT goods imports (% total goods imports)",
	"Insurance and financial services (% of commercial service imports)",
	"Manufactures imports (% of merchandise imports)",
	"Ores and metals imports (% of merchandise imports)",
	"Merchandise imports from economies in the Arab World (% of total merchandise imports)",
	"Merchandise imports (current US$)",
	"Merchandise imports from high-income economies (% of total merchandise imports)",
	"Merchandise imports from low- and middle-income economies outside region (% of total merchandise imports)",
	"Merchandise imports from low- and middle-income economies in East Asia & Pacific (% of total merchandise imports)",
	"Merchandise imports from low- and middle-income economies in Europe & Central Asia (% of total merchandise imports)",
	"Merchandise imports from low- and middle-income economies in Latin America & the Caribbean (% of total merchandise imports)",
	"Merchandise imports from low- and middle-income economies in Middle East & North Africa (% of total merchandise imports)",
	"Merchandise imports from low- and middle-income economies in South Asia (% of total merchandise imports)",
	"Merchandise imports from low- and middle-income economies in Sub-Saharan Africa (% of total merchandise imports)",
	"Merchandise imports by the reporting economy, residual (% of total merchandise imports)",
	"Merchandise imports by the reporting economy (current US$)",
	"Merchandise imports from low- and middle-income economies within region (% of total merchandise imports)",
	"Import value index (2000 = 100)",
	"Computer, communications and other services (% of commercial service imports)",
	"Commercial service imports (current US$)",
	"Transport services (% of commercial service imports)",
	"Travel services (% of commercial service imports)",
	"Net barter terms of trade index (2000 = 100)",
	"Medium and high-tech exports (% manufactured exports)",
	"Export volume index (2000 = 100)",
	"Export unit value index (2000 = 100)",
	"Agricultural raw materials exports (% of merchandise exports)",
	"Food exports (% of merchandise exports)",
	"Fuel exports (% of merchandise exports)",
	"ICT goods exports (% of total goods exports)",
	"Insurance and financial services (% of commercial service exports)",
	"Manufactures exports (% of merchandise exports)",
	"Ores and metals exports (% of merchandise exports)",
	"Merchandise exports to economies in the Arab World (% of total merchandise exports)",
	"Merchandise exports (current US$)",
	"Merchandise exports to high-income economies (% of total merchandise exports)",
	"Merchandise exports to low- and middle-income economies outside region (% of total merchandise exports)",
	"Merchandise exports to low- and middle-income economies in East Asia & Pacific (% of total merchandise exports)",
	"Merchandise exports to low- and middle-income economies in Europe & Central Asia (% of total merchandise exports)",
	"Merchandise exports to low- and middle-income economies in Latin America & the Caribbean (% of total merchandise exports)",
	"Merchandise exports to low- and middle-income economies in Middle East & North Africa (% of total merchandise exports)",
	"Merchandise exports to low- and middle-income economies in South Asia (% of total merchandise exports)",
	"Merchandise exports to low- and middle-income economies in Sub-Saharan Africa (% of total merchandise exports)",
	"Merchandise exports by the reporting economy, residual (% of total merchandise exports)",
	"Merchandise exports by the reporting economy (current US$)",
	"Merchandise exports to low- and middle-income economies within region (% of total merchandise exports)",
	"Export value index (2000 = 100)",
	"Computer, communications and other services (% of commercial service exports)",
	"High-technology exports (% of manufactured exports)",
	"Battle-related deaths (number of people)",
	"Internally displaced persons, new displacement associated with conflict and violence (number of cases)",
	"Intentional homicides (per 100,000 people)",
	"Presence of peace keepers (number of troops, police, and military observers in mandate)"
  )


}

prepare_wdi_files = function() {
  setwd("D:/libraries/dataquiz/wdi")
  dat = readRDS("wdi_data.Rds")

  key = dat %>%
    select(series_code, country_code) %>%
    unique()

  codes = unique(dat$series_code)[1:5]
  files.dir = "D:/libraries/dataquiz/wdi_files"

}

make_wdi_files = function(dat, codes, files.dir) {
  df = dat %>%
    filter(series_code %in% codes)
  code = codes[1]
  for (code in codes) {
    dir = file.path(files.dir, code)
    if (!dir.exists(dir)) {
      dir.create(dir)
    }
    d = filter(df, series_code == code)
    li = split(d,d$country_code)
    for (cou in names(li)) {
      el = li[[cou]]
      if (NROW(el)>0) {
        file = file.path(dir, paste0(cou,".Rds"))
        saveRDS(el[,c("year","value")], file)
      }
    }
  }

}
skranz/wdiquiz documentation built on March 11, 2020, 4:17 a.m.