Skip to content

Instantly share code, notes, and snippets.

View khakieconomics's full-sized avatar

Jim khakieconomics

View GitHub Profile
@khakieconomics
khakieconomics / stan_stan.stan
Created September 23, 2018 14:52
Censored time and group random effects normal linear model.
data {
int N; // number of observations
int T; // number of time periods
int I; // number of groups
int P; // number of controls
int<lower = 1, upper = T> time[N]; // time index
int<lower = 1, upper = I> group[N]; // group index
vector[N] Y;
matrix[N, P] X; // you should include group/time means in X
}
functions {
matrix make_pairwise_logit_mat(vector theta) {
matrix[rows(theta), rows(theta)] out;
for(r in 1:rows(out)) {
for(c in 1:r) {
if(r==c) {
out[r, c] = 0;
} else {
out[r, c] = exp(theta[c])/(exp(theta[c]) + exp(theta[r]));
@khakieconomics
khakieconomics / matrix_completion.stan
Created November 27, 2018 01:02
A simple matrix completion model for fixed K in Stan
data {
int N; // number of individuals
int T; // number of time periods
matrix[N, T] Y; // outcome matrix; missing entries set to -9.0
int K; // rank of matrix
}
parameters {
matrix[N, K] M; // individual loadings
matrix[T, K] U; // time factors
real<lower = 0> sigma; // error scale
@khakieconomics
khakieconomics / albert_chib_style_trivariate.stan
Created January 30, 2019 00:54
Trivariate model with a binary margin
data {
int N;
int N_neg;
int N_pos;
int P;
matrix[N, P] X;
matrix[N, 3] Y_raw; // first column is 0s and 1s
int pos_neg[N_neg];
int pos_pos[N_pos];
}
@khakieconomics
khakieconomics / Predocs_tracking_and_DiD.R
Last active October 9, 2019 21:08
File to ping Github's API, get the commit numbers for applicants to our predoc program, and run a simple DiD on their daily commits before and after the program.
# A simple script to grab github commits for a list of users and plot
# Group average commits per day for two groups
# To use this script, you'll need to set up a yaml file with credentials
# for github, and set up a google sheet with columns `Github handle` and
#`Attended` (with values "Yes" or "No")
# Author: Jim Savage, Schmidt Futures
# Load libraries
library(tidyverse); library(httr); library(yaml);library(jsonlite);

Keybase proof

I hereby claim:

  • I am khakieconomics on github.
  • I am javage (https://keybase.io/javage) on keybase.
  • I have a public key ASCOfa5tiUHOtFlCuiaEWO_BO1GQwq0-7ugZRerDYO_p7go

To claim this, I am signing this object: