Skip to content

Instantly share code, notes, and snippets.

View bgall's full-sized avatar

bgall bgall

View GitHub Profile
@bgall
bgall / Estimate models with groups of variables.R
Last active June 23, 2018 21:15
Estimate models with groups of variables
# Create sample data
set.seed(1)
data <- data.frame(y = rnorm(10),
a = rnorm(10),
b = rnorm(10),
c = rnorm(10),
d = rnorm(10))
# Function takes a string
@bgall
bgall / sample_selection_bias
Created February 14, 2018 19:42
Conditioning on the dependent variable changes the L in LATE
# Load packages
library(dplyr)
# Create data
set.seed(1)
x <- rnorm(1000000, mean = 0, sd = 1)
y <- x*x
full <- data.frame(x, y)
@bgall
bgall / r_na_examples
Last active July 6, 2017 18:32
Demonstrates the idiosyncratic behavior of NA values in R
# The below demonstrates the madness of R's treatment of NA values.
# Some examples taken from https://stackoverflow.com/questions/25100974/na-matches-na-but-is-not-equal-to-na-why/25101796
# Logical examples
NA %in% NA
# [1] TRUE
NA == NA