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
# intro to instrumental variables | |
# author: sebastian daza | |
# load libraries | |
library(simsem) | |
library(data.table) | |
library(texreg) | |
library(ivpack) | |
library(lme4) |
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
public void sqlToCSV (ResultSet rs, String filename) { | |
try { | |
FileWriter fw = new FileWriter(filename + ".csv"); | |
int cols = rs.getMetaData().getColumnCount(); | |
for(int i = 1; i <= cols; i ++){ | |
fw.append(rs.getMetaData().getColumnLabel(i)); | |
if(i < cols) fw.append(','); | |
else fw.append('\n'); | |
} | |
while (rs.next()) { |
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
# stratified sampling example and weighted means | |
set.seed(1) | |
library(data.table) | |
dat = data.table( | |
ID = 1:100, | |
A = sample(c("AA", "BB", "CC", "DD", "EE"), 100, replace = TRUE), | |
B = rnorm(100), C = abs(round(rnorm(100), digits=1)), | |
D = sample(c("CA", "NY", "TX"), 100, replace = TRUE), |
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
# author: sebastian daza | |
# web: sdaza.com | |
# libraries | |
library(data.table) | |
library(xtable) | |
# create descriptive tables |
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
import re | |
from pyspark.sql import Row | |
from pyspark.ml.classification import LogisticRegression | |
from pyspark.ml.feature import HashingTF, Tokenizer | |
from pyspark.sql.types import DoubleType | |
from operator import add | |
from lxml import etree | |
# from pyspark.sql import SQLContext | |
# sqlContext = SQLContext(sc) |
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
# load data | |
load("ex.Rdata") | |
################################### | |
# example only using mice package | |
################################### | |
library(mice) | |
imp <- mice(ex, maxit = 0) |
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
# EXAMPLES USING PACKAGE ACSR | |
# AUTHOR: SEBASTIAN DAZA | |
# March 23, 2015, 8:19 AM | |
# INSTALL LAST VERSION OF DATA.TABLE AND ACS PACKAGE (YOU HAVE TO INSTALL DEVTOOLS BEFORE!) | |
# I ASSUME ACS IS ALREADY INSTALLED! | |
install.packages("devtools") | |
devtools::install_github("Rdatatable/data.table", build_vignettes = FALSE) | |
# INSTALL MY PACKAGE |
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(acs) | |
rm(list=ls(all=TRUE)) | |
variables <- c("C17002_002", "C17002_003", "C17002_004", "C17002_005","C17002_006", "C17002_001") | |
dat <- acs.fetch(geo = geo.make(state = "WI", county = "*", tract = "*"), variable = variables) | |
p_output <- divide.acs(dat[,1] + dat[,2] + dat[,3] + dat[,4] + dat[,5], dat[,6], method = "proportion") | |
r_output <- divide.acs(dat[,1] + dat[,2] + dat[,3] + dat[,4] + dat[,5], dat[,6], method = "ratio") |
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
########### | |
# Example | |
########## | |
library(igraph) | |
actors <- data.frame(name=c("Alice", "Bob", "Cecil", "David", | |
"Esmeralda"), | |
age=c(48,33,45,34,21), | |
gender=c("F","M","F","M","F")) |
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
# MY R FUNCTIONS | |
# AUTHOR: SEBASTIAN DAZA | |
# Jun 02, 2014, 10:35 AM | |
# LOOKING FOR VARIABLES #### | |
lookvar <- function(dat, varnames) { | |
n <- names(dat) | |
nn <- list() | |
for (i in 1:length(varnames)) { |
NewerOlder