Skip to content

Instantly share code, notes, and snippets.

View svmiller's full-sized avatar
🤷‍♂️
¯\_(ツ)_/¯

Steven V. Miller svmiller

🤷‍♂️
¯\_(ツ)_/¯
View GitHub Profile
@svmiller
svmiller / 0-make-diff-formats.R
Last active February 19, 2020 16:07
Make/Test Various GSS Formats
setwd("~/Dropbox/data/gss/GSS_spss-2018")
library(tidyverse)
# haven::read_sav method -----
# ----------------------------
readsav_times = data.frame()
for(i in 1:10) {
@svmiller
svmiller / gsstimes.csv
Last active February 19, 2020 16:09
An experiment with various read/save times.
user.self sys.self elapsed user.child sys.child Method Category
20.027000000000044 0.9840000000000018 21.006000000000085 0 0 base::readRDS Read Times
17.839999999999918 0.847999999999999 18.68399999999997 0 0 base::readRDS Read Times
18.113000000000056 0.5360000000000014 18.643999999999778 0 0 base::readRDS Read Times
18.394000000000005 0.3640000000000043 18.75299999999993 0 0 base::readRDS Read Times
19.273999999999887 0.015999999999998238 19.284000000000106 0 0 base::readRDS Read Times
19.51299999999992 0.2079999999999984 19.715000000000146 0 0 base::readRDS Read Times
19.71699999999987 0.6000000000000014 20.311999999999898 0 0 base::readRDS Read Times
19.740999999999985 0.5080000000000027 20.242999999999938 0 0 base::readRDS Read Times
19.47199999999998 0.5960000000000036 20.063000000000102 0 0 base::readRDS Read Times
@svmiller
svmiller / 1-show-gdp-growth-pwt9.R
Last active October 23, 2019 14:48
Show post-war GDP growth in the top 3 LA, European, and Asian economies (1950-ish-1980)
library(pwt9)
library(tidyverse)
library(stevemisc)
pwt9.1 %>% tbl_df() -> pwt
pwt %>%
filter(country %in% c("Germany", "United Kingdom", "France",
"Mexico", "Brazil", "Argentina",
@svmiller
svmiller / strategic_rivalries.csv
Last active April 3, 2021 20:20
Strategic Rivalries, 1494-2010
rivalryno rivalryname sidea sideb styear endyear region type1 type2 type3
1 Austria-France Austria France 1494 1918 European GPs spatial positional
2 Austria-Ottoman Empire Austria Ottoman Empire 1494 1908 European GPs spatial positional
4 France-Spain France Spain 1494 1700 European GPs positional spatial
3 Britain-France 1 Great Britain France 1494 1716 European GPs spatial positional
5 Ottoman Empire-Spain Ottoman Empire Spain 1494 1585 European GPs spatial positional
6 Ottoman Empire-Venice Ottoman Empire Venice 1494 1717 European GPs spatial positional
7 Portugal-Spain Portugal Spain 1494 1580 European GPs spatial positional
8 Portugal-Venice Portugal Venice 1494 1580 European GPs positional
9 Ottoman Empire-Portugal Ottoman Empire Portugal 1501 1580 European GPs positional
@svmiller
svmiller / 1-dont-bring-boilerplate-centrist-talking-points-to-a-data-fight-claire.R
Created July 31, 2019 16:23
“fReE sTuFf fRoM tHe gOvErnMeNt dOeS nOt pLaY wElL iN tHe mIdWeSt.”
library(tidyverse)
library(stevemisc)
GSS <- readRDS("~/Dropbox/data/gss/GSS_spss-2018/gss7218.rds")
GSS %>%
mutate(regioncondensed = NA,
regioncondensed = ifelse(region == 8 | region == 9, "West", regioncondensed),
regioncondensed = ifelse(region == 3 | region == 4, "Midwest", regioncondensed),
regioncondensed = ifelse(region == 5 | region == 6 | region == 7, "South", regioncondensed),
@svmiller
svmiller / 1-westernjackman1994bicr.R
Last active June 11, 2019 16:55
Cross-National Rates of Trade Union Density (A Replication of Western and Jackman (1994), using the brms package)
library(stevemisc)
library(tidyverse)
options(mc.cores=parallel::detectCores())
data(uniondensity)
M1 <- lm(union ~ left + size + concen, data=uniondensity)
library(brms)
@svmiller
svmiller / nixon-disapproval-rating-cpi-previous-period.R
Last active May 30, 2019 22:19
Nixons's Disapproval Rating vis-a-vis the Growth Rate in the CPI to Same Period, Previous Year
library(fredr)
library(stevemisc)
library(lubridate)
Approv <- read_csv("~/Dropbox/data/potus-approval/potus-approval-monthly-average.csv")
fredr(series_id = "CPALTT01USM659N",
observation_start = as.Date("1968-01-01"),
observation_end = as.Date("1981-01-01")) -> cpi_nixon
@svmiller
svmiller / partisanship-pet-ownership.R
Last active May 28, 2019 13:11
The Partisanship of Pet Ownership
library(tidyverse)
library(stevemisc)
GSS <- readRDS("~/Dropbox/data/gss/GSS_spss-2018/gss7218.rds")
GSS %>%
select(year, cat, dog, partyid, polviews) %>%
filter(year == 2018) %>%
mutate(catnodog = ifelse(cat == 1 & dog == 0, 1, 0),
dognocat = ifelse(dog == 1 & cat == 0, 1, 0),
nodognocat = ifelse(cat == 0 & dog == 0, 1, 0),
library(blscrapeR)
library(tidyverse)
library(stevemisc)
bls_api(c("CUSR0000SS30021", # laundry equipment
"CUSR0000SEHK02", # other appliances
"CUSR0000SEHJ", # furniture and bedding
"CUSR0000SETC", # motor vehicle parts
"CUUR0000SEHH01", # floor coverings (NSA)
"CUSR0000SERC01", # sports vehicles (including bicycles)
@svmiller
svmiller / breakdown-dems-repubs-cces-2018.R
Created May 4, 2019 18:28
Breakdown of Democrats and Republicans, by Age, Education, and Ideology (CCES, 2018)
library(tidyverse)
CCES <- haven::read_dta("~/Dropbox/data/cces/2018/CCES2018_OUTPUT.dta") %>%
rename_all(tolower)
CCES %>% # don't forget to collect educ
mutate(agenum = 2018 - birthyr,
sex = ifelse(gender == 2, "Female", "Male"),
pid = ifelse(pid7 %in% c(1,2,3), "Democrat", NA),
pid = ifelse(pid7 %in% c(5,6,7), "Republican", pid),
pid = ifelse(pid7 %in% c(4,8,9,98,99), "Independent", pid),