Skip to content

Instantly share code, notes, and snippets.

View RandomCriticalAnalysis's full-sized avatar

Random Critical Analysis RandomCriticalAnalysis

View GitHub Profile
We can make this file beautiful and searchable if this error is corrected: It looks like row 7 should actually have 13 columns, instead of 9. in line 6.
tractStr,fid,geoid,population,poverty_rate,median_income,pct_white,pct_asian,pct_black,pct_white_or_asian,shootings,shooting_rate,shooting_rate_yj_transform
000100,1,42101000100,4166,0.06937109937590015,102448,0.7366778684589534,0.04392702832453192,0.07513202112337974,0.7806048967834853,0,0,-1.3860356463057237
000200,2,42101000200,2576,0.29253365973072215,47243,0.2080745341614907,0.11995341614906832,0.0562888198757764,0.328027950310559,2,0.78,-0.60289626497475
000300,3,42101000300,3444,0.09255219694608913,91354,0.6387921022067363,0.05400696864111498,0.06416957026713124,0.6927990708478513,1,0.29,-1.0267090442254603
000401,4,42101000401,2591,0.17697394010112796,62821,0.6086453106908529,0.06831339251254342,0.12118873021999228,0.6769587032033964,0,0,-1.3860356463057237
000402,5,42101000402,3880,0.04690721649484536,78648,0.8378865979381444,0.038402061855670105,0.05515463917525773,0.8762886597938144,5,1.29,-0.2935049723600755
000500,6,42101000500,2471,0.33153638814016173,43702,0.3537029542695265,0.0453257790368272,
fips bea_ea_code bea_ea_name pop10 county_name gdp2018
1001 114 Montgomery-Alexander City, AL 54571 Autauga, AL 1690937
1003 112 Mobile-Daphne-Fairhope, AL 182265 Baldwin, AL 6606080
1005 48 Dothan-Enterprise-Ozark, AL 27457 Barbour, AL 851956
1007 19 Birmingham-Hoover-Cullman, AL 22915 Bibb, AL 424510
1009 19 Birmingham-Hoover-Cullman, AL 57322 Blount, AL 942904
1011 114 Montgomery-Alexander City, AL 10914 Bullock, AL 256130
1013 114 Montgomery-Alexander City, AL 20947 Butler, AL 632592
1015 19 Birmingham-Hoover-Cullman, AL 118572 Calhoun, AL 4428092
1017 11 Atlanta-Sandy Springs-Gainesville, GA-AL 34215 Chambers, AL 2218892
stated %>%
filter(
!is.na(region),
date >= as.Date("2020-03-01"),
state %in% c('NY','NJ','CT','MA','PA')
) %>%
mutate(
date_from=as.integer(date - as.Date("2020-03-01")),
value=death/pop*10^6
) %>%
library(tidyverse)
library(readxl)
library(httr)
library(countrycode)
library(janitor)
library(hrbrthemes)
library(ggrepel)
library(scales)
library(zoo)
#devtools::install_github("slowkow/ggrepel")
# FROM: https://github.com/JonMinton/COVID-19
DF = tidied_data %>%
filter(type == "confirmed") %>%
mutate(
higher = case_when(
higher == "Iran (Islamic Republic of)" ~ "Iran",
higher == "Hong Kong SAR" ~ "Hong Kong",
@RandomCriticalAnalysis
RandomCriticalAnalysis / oecd_examples_helper_fn.R
Created November 22, 2019 17:45
Quick examples for helper OECD helper functions
source("oecd_helper_library.R")
# example of how to fetch parameter info from within R
sna1_filter_short=show_filter_options('SNA_TABLE1',showLong=F)
sna1_filter_long=show_filter_options('SNA_TABLE1',showLong=T)
@RandomCriticalAnalysis
RandomCriticalAnalysis / oecd_helper_library.R
Created November 22, 2019 17:43
Helper functions to make using OECD package easier
library(tidyverse)
library(OECD)
# global variable to cache data structure in memory
# this is crudely implemented, but much faster than hitting OECD.stat constantly
if (!exists("oecd_cached_structures")) {
oecd_cached_structures=list()
} else {
warning("oecd_cached_structures already set. You can delete the object if you wish to clear....")
@RandomCriticalAnalysis
RandomCriticalAnalysis / state_fiscal_test_score_correlation_example.R
Created May 7, 2018 14:36
Snippet to create correlation plot by state between school test scores and per pupil fiscal measures
library(dplyr)
library(reshape2)
library(ggplot2)
DataPath="." # you may need to update this if not working from same path
setwd(DataPath)
# Data from version 2.0 of covariates and pooled score estimates from SEDA
# https://cepa.stanford.edu/seda/data-archive
@RandomCriticalAnalysis
RandomCriticalAnalysis / make_icp_data.R
Created January 27, 2018 00:27
Snippet to create ICP series with WHO NHE figures at PPPs for AIC and GDP
require(dplyr)
require(janitor)
require(reshape2)
require(countrycode)
icp_raw = read.csv("ext_data/WorldBank_icp_2011.csv", stringsAsFactors = F) %>%
filter(
Country.Code != '' # remove blank lines and notes at end of file
) %>%
@RandomCriticalAnalysis
RandomCriticalAnalysis / seda_relevant_snippet.R
Last active May 31, 2016 21:41
for Anatoly (relevant code for education analysis)
# test scores and most covariates taken from
# https://cepa.stanford.edu/seda/download?nid=1727&destination=node/1717
# parents average years of education computed using data from census ACS (via dept of edu EDGE service)
# http://nces.ed.gov/programs/edge/demographicACS.aspx
pm = read.csv("cepa_pooled_means.csv",stringsAsFactors = F)
cve = read.csv("cepa_covariates_from_excel.csv",stringsAsFactors = F)
glarge = merge(cve,pm,by.x='leaid',by.y='nces_district_id')