View lazy_way_to_install_all_R_packages.sh
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
# Find all your R files & get just the package names, uniquely | |
find ../analysis/ -name *R -print0 | xargs -0 grep -h 'library*' | sed 's/library//g' | sed 's/#//g' | sed 's/ //g' | sort | uniq|\ | |
sed 's/(//g' | sed 's/)//g' > package_list.txt | |
# Install each package | |
cat package_list.txt | xargs -I {} Rscript -e 'install.packages("{}")' |
View coef plot.R
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
#!/usr/bin/Rscript --vanilla | |
suppressPackageStartupMessages({ | |
library(magrittr) | |
library(dplyr) | |
library(foreign) | |
library(plm) | |
library(reshape2) | |
library(stargazer) | |
library(ggplot2) |
View Makefile
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
project_name = hot_towel | |
ts := $(shell /bin/date "+%Y-%m-%d---%H-%M-%S") | |
params = | |
# DONE | |
params += params_exp_details.tex | |
params_exp_details.tex: ../analysis/params_exp_details.R | |
cd ../analysis && ./params_exp_details.R |
View uc_salaries_by_dept_and_rank.R
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(XML) | |
library(ggplot2) | |
df <- readHTMLTable("http://projects.dailycal.org/paychecker/departments/")[[1]] | |
DeMoney <- function(x) as.numeric(gsub(",", "", gsub("\\$", "", as.character(x)))) | |
money.columns <- c("All", "Professor", "Associate professor", "Assistant professor", | |
"Lecturer") |
View geofacet_usage_example.R
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(geofacet) # my forked version | |
library(ggplot2) | |
library(jsonlite) | |
library(ggrepel) | |
# grab top cities | |
cities <- fromJSON("https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json") | |
n <- 50 | |
x <- cities$longitude[1:n] |
View simualte_bartik.R
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(lfe) | |
library(stargazer) | |
set.seed(6152011) | |
# Number of cities | |
L <- 1000 | |
# Number of industries | |
K <- 3 |
View simulate_experiment.R
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
SimExperiment <- function(num.groups, sample.size, beta, randomize.by.group = FALSE){ | |
"Simulate running an analysis of the experiment with linear regression" | |
df <- CreateClusteredData(num.groups, sample.size, beta, randomize.by.group = randomize.by.group) | |
m <- lm(y ~ trt, data = df) | |
c(as.numeric(coef(m)[2]), as.numeric(sqrt(diag(vcov(m))[2]))) | |
} |
View simulate_clustered_data.R
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
CreateClusteredData <- function(num.groups, sample.size, beta, randomize.by.group = FALSE){ | |
individual <- 1:sample.size # index for individuals | |
group <- sample(1:num.groups, size = sample.size, replace = TRUE) # randomly assign everyone to a group | |
group.effect <- rnorm(num.groups) # create a group-specific effect | |
eta <- group.effect[group] # give each individual their group-specific effect | |
epsilon <- rnorm(sample.size) # given each individual an individual-specific effect | |
if (randomize.by.group){ | |
group.trt.assignment <- rbinom(num.groups, 1, 0.5) | |
trt <- group.trt.assignment[group] | |
} else { |
View gist:118e251163515ef5703f
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
ts := $(shell /bin/date "+%Y-%m-%d---%H-%M-%S") | |
project.pdf: project.bib project.tex | |
pdflatex -interaction=nonstopmode project | |
bibtex project | |
pdflatex -interaction=nonstopmode project | |
pdflatex -interaction=nonstopmode project | |
backup: | |
tar --exclude='../backups' -zcvf ../backups/project_$(ts).tar.gz ../ |
View strat.R
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(ggplot2) | |
# simulate experiments using stratification and randomization and report | |
# absolute difference in estimates from true treatment effect, tau. | |
simExp <- function(n, tau, beta = 3){ | |
x <- sort(runif(n)) | |
W.rand <- rbinom(n,1,0.5) | |
W.strat <- rep(c(0,1), n/2) | |
epsilon <- rnorm(n, 0, 0.5) |
NewerOlder