Skip to content

Instantly share code, notes, and snippets.

@benzipperer
benzipperer / README.md
Last active October 7, 2016 19:01
Extension of Tables 1A and 2 of Schmitt and Zipperer (2007), "The Decline in African-American Representation in Unions and Manufacturing, 1979-2007", Center for Economic and Policy Research

Table 1A. Share of Workers in Unions, by Race or Ethnicity, 1983-2015 (Percent)

Black White Hispanic Overall
1979 . . . .
1980 . . . .
1981 . . . .
1982 . . . .
1983 31.7 22.2 24.2 23.3
1984 29.1 20.5 22.8 21.5
@benzipperer
benzipperer / stats_server_howto.md
Last active December 10, 2020 21:19
Routine tasks for stats server

Instructions for user management on our stats server

User basics

Create a new user

sudo adduser --disabled-password newuser

Most users do not have passwords and instead use SSH keys for authentication. If you need to add or change a password, try

@benzipperer
benzipperer / toshiba5540c_print_howto.md
Last active September 13, 2016 13:53
printing on a toshiba 5540c in fedora

Download the 5540c drivers for CUPS duplex printing, from http://business.toshiba.com/usa/support/downloads.jsp?site=usa

cd /tmp
wget http://business.toshiba.com/downloads/KB/f1Ulds/14078/TOSHIBA_ColorMFP_CUPS.tar

Extract the files (they will be placed in /usr) and rename the .ppd file

cd /
sudo tar -xvf /tmp/TOSHIBA_ColorMFP_CUPS.tar
@benzipperer
benzipperer / county2010_cbsa2010_geocorr14.csv
Last active September 8, 2017 20:30
rural urban employment
county cbsa10 cbsatype10 cntyname cbsaname10 pop10 afact
county cbsa10 cbsatype10 cntyname 2010 CBSA Name Total Pop, 2010 census county to cbsatype10 alloc factor
1001 33860 Metro Autauga AL Montgomery, AL Metropolitan Statistical Area 54571 1
1003 19300 Metro Baldwin AL Daphne-Fairhope-Foley, AL Micropolitan Statistical Area 182265 1
1005 21640 Micro Barbour AL Eufaula, AL-GA Micropolitan Statistical Area 27457 1
1007 13820 Metro Bibb AL Birmingham-Hoover, AL Metropolitan Statistical Area 22915 1
1009 13820 Metro Blount AL Birmingham-Hoover, AL Metropolitan Statistical Area 57322 1
1011 99999 Bullock AL 99999 10914 1
1013 99999 Butler AL 99999 20947 1
1015 11500 Metro Calhoun AL Anniston-Oxford, AL Metropolitan Statistical Area 118572 1
@benzipperer
benzipperer / cpi.R
Created September 12, 2017 18:10
cumulative product in R
rm(list = ls())
library(dplyr)
# first generate some fake data
mydata <- data.frame(
year=rep(2001:2020,each=12),
month=rep(1:12,times=20),
cpiw67=runif(20*12,0,2.5)
)
mydata <- mutate(mydata,
@benzipperer
benzipperer / git_tips.md
Last active May 4, 2018 16:23
tips for using git

start with latest remote master branch

reset the repo's local copy of the master to match the latest remote version (source)

git checkout master
git fetch
git reset --hard origin/master

branch basics

List branches: git branch

@benzipperer
benzipperer / Rtips.md
Last active March 27, 2018 22:54
R tips

clearing workspaces

Remove almost everything (functions, data, ...). This will not produce any errors.

rm(list = ls())

Remove user-loaded packages. This may produce errors.

lapply(paste0('package:',names(sessionInfo()$otherPkgs)),detach,character.only=TRUE,unload=TRUE)
@benzipperer
benzipperer / problems
Last active April 3, 2018 22:55
problematic import
setwd("/data/nlsy/data/raw/nlsy97_all_1997-2013")
head -n 1 nlsy97_all_1997-2013 > data.dat
read_delim("data.dat",delim=" ",)
read_delim("data.dat",delim=" ",col_types = cols(.default = col_integer()))
read_delim("data.dat",delim=" ",col_names=FALSE,col_types = cols(.default = col_integer()))
read_delim(pipe("cut -d \" \" -f1-8 data.dat"),delim=" ",col_names=FALSE,col_types = cols(.default = col_integer()))
newdata<-read_delim(pipe("cut -d \" \" -f1-10000 nlsy97_all_1997-2013.dat"),delim=" ",col_names=FALSE)
@benzipperer
benzipperer / readme.md
Last active March 6, 2019 05:02
r package workflow

build

make R .rd documentation using roxygen (in man/): devtools::document()

need to knit root README (seems like devtools might be able to do this too?)

build vignettes (in doc/): devtools::build_vignettes()

build pkgdown site (in docs/): pkgdown::build_site()

install

@benzipperer
benzipperer / bouts.R
Created March 12, 2019 04:57
spells in R
library(dplyr)
# just used to simulate some data
library(purrr)
# create fake data
f <- function(x,i) {
return(data.frame(bout=x, element=i))
}
fake_data <- map_dfr(1:4, ~map2_dfr(.x, 0:(round(runif(1)*10)+5), f)) %>%
mutate(invisible_id=ifelse(element==0,"bout","element")) %>%