This file contains hidden or 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
#################### | |
# Create relogit predicted probabilities using Zelig and ggplot2 | |
# Two Sword Lengths: Losers' Consent and Violence in National Legislatures (Working Paper 2012) | |
# Christopher Gandrud | |
# Updated 26 April 2012 | |
################### | |
## Load required packages | |
library(RCurl) | |
library(Zelig) |
This file contains hidden or 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
################# | |
# Use R to recreate part of QMV the relative non-proportional hazard estimation graph (fig 2) from Licht (2011) | |
# Christopher Gandrud (http://christophergandrud.blogspot.com/) | |
# 4 October 2012 | |
################# | |
#### Set Up #### | |
# Load required libraries |
This file contains hidden or 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
################## | |
# Compare relative non-proportional hazards | |
# Christopher Gandrud | |
# 4 October 2012 | |
################## | |
# Load required libraries | |
library(survival) | |
library(MSBVAR) | |
library(reshape) |
This file contains hidden or 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
############### | |
# NPL Relative Hazard 2 | |
# Christopher Gandrud | |
# 6 October 2012 | |
############### | |
# Load required libraries | |
library(foreign) | |
library(survival) | |
library(MSBVAR) |
This file contains hidden or 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
################# | |
# Use R to recreate part of QMV the relative non-proportional hazard estimation graph (fig 2) from Licht (2011) | |
# Updated to keep only the middle 95% of simulations | |
# Christopher Gandrud (http://christophergandrud.blogspot.com/) | |
# 30 December 2012 | |
################# | |
#### Set Up #### |
This file contains hidden or 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
##################### | |
# R function for downloading plain-text data from GitHub | |
# Christopher Gandrud | |
# 7 January 2013 | |
##################### | |
# source_GitHubData is directly based on source_url from the Hadley Wickham's devtools package | |
source_GitHubData <-function(url, sep = ",", header = TRUE) | |
{ |
This file contains hidden or 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
############### | |
# LoadandCite: a function for installing, loading, and creating a BibTeX bibliography of R packages. | |
# Christopher Gandrud | |
# 9 January 2013 | |
############## | |
# This function is partially based on: https://gist.github.com/3710171 | |
LoadandCite <- function(packages, file = "", install = FALSE) | |
{ |
This file contains hidden or 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
#' An R function for filling in missing values of a variable from one data frame with the values from another variable. | |
#' | |
#' \code{FillIn} uses values of a variable from one data set to fill in missing values in another. | |
#' | |
#' @param D1 the data frame with the variable you would like to fill in. | |
#' @param D2 the data frame with the variable you would like to use to fill in \code{D1}. | |
#' @param Var1 a character string of the name of the variable in \code{D1} you want to fill in. | |
#' @param Var2 an optional character string of variable name in \code{D2} that you would like to use to fill in. | |
#' @param KeyVar a character vector of variable names that are shared by \code{D1} and \code{D2} that can be used to join the data frames. | |
#' |
This file contains hidden or 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
############ | |
# stataDo: A function for running Stata do files in batch mode from R | |
# Christopher Gandrud | |
# 22 January 2013 | |
############ | |
# Note: Stata must be in your PATH for this to work. | |
## For Mac Users see: http://www.stata.com/support/faqs/mac/advanced-topics/ | |
stataDo <- function(dofile, options = "-e"){ |
This file contains hidden or 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
quarter_year <- function(x, with_year = FALSE) { | |
require(lubridate) | |
m <- month(x) | |
quarters <- c("1" = 1, | |
"2" = 1, | |
"3" = 1, | |
"4" = 2, | |
"5" = 2, | |
"6" = 2, | |
"7" = 3, |