install.packages("devtools")
install.packages("roxygen2")
devtools::install_github("ben-aaron188/rgpt3")
LETTERS
letters
letters[30]
letters[27]
1-721
1-0.721
2.279*276.5
5.279*276.5
3.279*276.5
install.packages("naniar")
4503/4430
4503/4430-1
install.packages("~/GitHub/hbal_1.2.10.tgz", repos = NULL, type = .Platform$pkgType)
install_github("xuyiqing/hbal", ref = 'v1.2.10')
devtools::install_github("xuyiqing/hbal", ref = 'v1.2.10')
devtools::install_github("xuyiqing/hbal", ref = 'v1.2.10')
devtools::install_github("xuyiqing/hbal", ref = 'v1.2.10', force = TRUE)
library(devtools)
help(install_github)
devtools::install_github("xuyiqing/hbal@*release")
devtools::install_github("xuyiqing/hbal@*release", force = TRUE)
500*15.78*0.03
500*15.78*0.06
500/15.78
3800*1.1
3800*1.05
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE,cache=TRUE)
knitr::opts_chunk$set(fig.width=7, fig.height=6, out.width = '70%', fig.align = "center")
rm(list=ls())
library(remotes)
library(kableExtra)
library(haven)
library(tidyverse)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE,cache=TRUE)
knitr::opts_chunk$set(fig.width=7, fig.height=6, out.width = '70%', fig.align = "center")
rm(list=ls())
library(remotes)
library(kableExtra)
library(haven)
library(tidyverse)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE,cache=TRUE)
knitr::opts_chunk$set(fig.width=7, fig.height=6, out.width = '70%', fig.align = "center")
rm(list=ls())
library(remotes)
library(kableExtra)
library(haven)
library(tidyverse)
library(ivmodel)
library(ggplot2)
library(doParallel)
library(foreach)
library(estimatr)
require(AER)
library(lfe)
library(glue)
#path <- "~/Dropbox/research/IV/IV Sensitivity"
path <- "~/Dropbox/ProjectZ/IV Sensitivity"
setwd(path)
knitr::opts_knit$set(root.dir = path)
#install_github("apoorvalal/ivDiag")
library(ivDiag)
# number of cores
cores <- 15
knitr::write_bib("references.bib")
#source("/Users/ziwenzu/Downloads/ivDiag-master/R/first_stage_tests.R")
#source("/Users/ziwenzu/Downloads/ivDiag-master/R/utils.R")
#source("/Users/ziwenzu/Downloads/ivDiag-master/R/AR_test.R")
# %% Meredith (2013) APSR data
df <-readRDS("./data/apsr_Meredith_2013.rds")
# Y: outcome of interest
Y <- "DemShareDB_res"
# D: endogenous treatment
D<-"DemShareGOV_res"
# Z: instrumental variable
Z <- "HomeGOV_res"
# covariates of control variables
controls <- "HomeDB_res"
# clusters
cl <- "fips"
# fixed effects
FE<- NULL
# weights
weights<-NULL
f<-first_stage_tests(data=df,  Y=Y, D=D, Z=Z, controls=controls,
FE =FE, cl =cl,weights=weights, cores =15, scatter = TRUE)
g<-ivDiag(data=df, Y=Y, D=D, Z=Z, controls=controls, FE =FE,
cl =cl,weights=weights, cores = 15)
g$est_ols
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE,cache=TRUE)
knitr::opts_chunk$set(fig.width=7, fig.height=6, out.width = '70%', fig.align = "center")
rm(list=ls())
library(remotes)
library(kableExtra)
library(haven)
library(tidyverse)
library(ivmodel)
library(ggplot2)
library(doParallel)
library(foreach)
library(estimatr)
require(AER)
library(lfe)
library(glue)
#path <- "~/Dropbox/research/IV/IV Sensitivity"
path <- "~/Dropbox/ProjectZ/IV Sensitivity"
setwd(path)
knitr::opts_knit$set(root.dir = path)
#install_github("apoorvalal/ivDiag")
library(ivDiag)
# number of cores
cores <- 15
knitr::write_bib("references.bib")
#source("/Users/ziwenzu/Downloads/ivDiag-master/R/first_stage_tests.R")
#source("/Users/ziwenzu/Downloads/ivDiag-master/R/utils.R")
#source("/Users/ziwenzu/Downloads/ivDiag-master/R/AR_test.R")
df <- readRDS("./data/ajps_Rueda_2017.rds")
Y <- "e_vote_buying" # Y: outcome of interest
D <-"lm_pob_mesa" # D: endogenous treatment
Z <- "lz_pob_mesa_f" # Z: instrumental variable
controls <- c("lpopulation", "lpotencial") # covariates of control variables
cl <- "muni_code" # clusters
FE <- weights <- NULL # no fixed effects or weights
df <- readRDS("./data/ajps_Rueda_2017.rds")
library(ivDiag)
data(ivDiag)
head(gsz_south)
head(gsz)
head(rueda)
rm(list = ls())
data(ivDiag)
library(ivDiag)
data(ivDiag)
force(gsz)
View(gsz)
force(gsz_south)
force(rueda)
help(hist)
56+48+40+7+51+57
48+40+7+51
56+49+40+7+50+61
help(inherits
)
650+250+450
380*2/15
library(testthat)
help(ivDiag)
library(ivDiag)
library(ivDiag)
help(ivDiag)
library(ivDiag)
help(ivDiag)
help(AR_test)
help(ivDiag)
library(ivDiag)
help(ivDiag)
600/15
library(kbal)
help(kbal)
devtools::install_github("ngreifer/cobalt")
install.packages("library(R.matlab)")
install.packages("R.matlab")
21/16
1557-887
install.packages("sensmakr")
install.packages("remote")
install.packages("fixest")
5120*2880/(3840*2160)
install.packages("gsynth")
install.packages("Hmisc")
install.packages("latex2exp")
install.packages("Qtools")
install.packages("optiSolve")
install.packages("ggpubr")
install.packages("Synth")
install.packages("~/Desktop/Synth_1.1-6.tar.gz", repos = NULL, type = "source")
install.packages("kernlab")
install.packages("optimx")
install.packages("rgenoud")
install.packages("LowRankQP")
install.packages("~/Desktop/LowRankQP_1.0.5.tar.gz", repos = NULL, type = "source")
install.packages("~/Desktop/Synth_1.1-6.tar.gz", repos = NULL, type = "source")
1.66/1.34
5/38
59/93
93-59
150*2/15
90-53
7+5+8+17
install.packages"qpdf"
install.packages("qpdf")
32500+6500
devtools::install_github("csterbenz1/KBAL", ref = "cat_kernel"))
devtools::install_github("csterbenz1/KBAL", ref = "cat_kernel")
88*50
70*0.7
5/20、4
5/20、4
5/20/4
20*1.06^4
60/400
install.packages("dplyr")
52+17
69/90
90*0.058
90*0.58
7/54
library(panelView)
help(panelview)
71/12*9
71/12
71000*7
153440/12
12796/7000
20*25
20*25/20
42+8+5+24
100*12*5
100*12*10
630000-7500
63000-7500
51400-7500
326*36+4600
18000*7
23/80
246-116
install.packages("sensemakr")
58.33*24
600/24
4+4+2+3+3+4
3+3+2+2+4
8+2+2+5+2+2+2+4
6+2+2+5+2+2+2+4
330*24
library(interflex)
install.packages("interflex")
library(interflex)
help(interflex)
install_all <- function(packages) {
installed_pkgs <- installed.packages()[, "Package"]
for (pkg in packages) {
if (!pkg %in% installed_pkgs) {
install.packages(pkg)
}
}
}
packages <- c("foreach", "future", "doParallel", "lfe", "fixest", "ggplot2",
"ggfortify", "wCorr", "haven", "glue", "patchwork", "testthat")
install_all(packages)
my.packages <- c("byCausal", "fect", "tjbal", "gsynth", "panelView", "ivDiag",
"hbal", "interflex")
install_all(my.packages)
install.packages("Rcpp", type = "source")
install.packages("RcppArmadillo", type = "source")
install.packages("Rcpp", type = "source")
remove.packages("hbal")
## ----include = FALSE------------------------------------------------------------------------------------------------
library(ggplot2)
library(estimatr)
require(ebal)
## ----message=FALSE--------------------------------------------------------------------------------------------------
library(hbal)
set.seed(1984)
N <- 1500
X1 <- rnorm(N)
X2 <- rnorm(N)
X3 <- rbinom(N, size = 1, prob = .5)
D_star <- 0.5 * X1 + 0.3 * X2 + 0.2 * X1 * X2 - 0.5 * X1 * X3 - 1
D <- ifelse(D_star > rnorm(N), 1, 0) # Treatment indicator
y <- 0.5 * D + X1 + X2 + X2 * X3 + rnorm(N) # Outcome
dat <- data.frame(D = D, X1 = X1, X2 = X2, X3 = X3, Y = y)
head(dat)
## ----fig.height = 6, fig.width = 6, fig.align = "left", dpi=100-----------------------------------------------------
library(ebal)
ebal.out <- ebalance(Treat = dat$D, X = dat[,c('X1', 'X2', 'X3')]) # ebal
hbal.out <- hbal(Treat = 'D', X = c('X1', 'X2', 'X3'),  Y = 'Y',  data = dat, expand.degree = 1) # hbal
hbal.out <- hbal(Treat = 'D', X = c('X1', 'X2', 'X3'),  Y = 'Y',  data = dat) # hbal
# plot weights
W <- data.frame(x = ebal.out$w, y = hbal.out$weights.co)
ggplot(aes(x = x, y = y), data = W) + geom_point() + theme_bw() +
labs(x = "ebal weights", y="hbal weights", title = "ebal weights vs. hbal weights")
help(att)
1983*12
185/297
1-0.62
21482/76,329.6
21482/76,329
21482/76329
17/23
46000+23000+7000
69000+7000
7000/500
7000/12
8290-2595
### Please set path to the root folder of the project ###
path <- "~/Dropbox/projectZ/IV Sensitivity/LLXZ_rep/" # please change this line
load("metadata/iv_replicate.rds")
### Please set path to the root folder of the project ###
path <- "~/Dropbox/projectZ/IV Sensitivity/LLXZ_rep/" # please change this line
setwd(path)
load("metadata/iv_replicate.rds")
# replicated F
d$f_replicated <- d$f_standard
d$f_replicated[which(d$original_estimation_f_type == "robust")] <- d$f_robust[which(d$original_estimation_f_type == "robust")]
d$f_replicated
getStat <- function(var, method = "mean") {
n <- nrow(d)
out <- rep(NA, 3)
if (method == "mean") {
out[1] <- round(mean(var[which(d$iv_type == "experiment")], na.rm = TRUE), 3)
out[2] <- round(mean(var[which(d$iv_type != "experiment")], na.rm = TRUE), 3)
out[3] <- round(mean(var, na.rm = TRUE), 3)
} else if (method == "median") {
out[1] <- round(median(var[which(d$iv_type == "experiment")], na.rm = TRUE), 2)
out[2] <- round(median(var[which(d$iv_type != "experiment")], na.rm = TRUE), 2)
out[3] <- round(median(var, na.rm = TRUE), 2)
}
names(out) <- c("Experimental", "Obervational", "All")
return(out)
}
# table structure
tb3 <- matrix(NA, 14, 3)
colnames(tb3) <- c("exp", "obs", "all")
rownames(tb3) <- c("unreported", "effF < 10", "bootF < 10", "med effF",
"p_orig insig", "p_AR insig", "p_bootc insig", "p_boott insig",
"p_tF insig", "same_sign", "ratio > 1", "ratio > 5", "ratio > 10",
"med ratio")
# Panel A: F stats
f.missing <- is.na(d$f_report)
tb3[1,] <- getStat(f.missing)
f.below10 <- (d$f_effective < 10)
tb3[2,] <- getStat(f.below10)
f.below10 <- (d$f_boot < 10)
tb3[3,] <- getStat(f.below10)
tb3[4,] <- getStat(d$f_effective, method = "median")
# Panel B: p values
d$iv_report_z <- d$iv_report_coef / d$iv_report_se
d$iv_report_p <- 2 * (1 - pnorm(abs(d$iv_report_z)))
p.report.insig <- d$iv_report_p > 0.05
tb3[5,] <- getStat(p.report.insig)
p.AR.insig <- (d$AR_p > 0.05 | d$AR_bounded == FALSE)
tb3[6,] <- getStat(p.AR.insig)
p.bootc.insig <- d$iv_bootc_p > 0.05
tb3[7,] <- getStat(p.bootc.insig)
p.boott.insig <- d$iv_boott_p > 0.05
tb3[8,] <- getStat(p.boott.insig)
p.tF.insig <- (d$tF_p > 0.05)
tb3[9,] <- getStat(p.tF.insig)
# Panel C. IV vs. OLS
samesign <- sign(d$iv_coef) == sign(d$ols_coef)
tb3[10,] <- getStat(samesign)
ratio.1 <- abs(d$iv_coef) >= 1 * abs(d$ols_coef)
tb3[11,] <- getStat(ratio.1)
ratio.5 <- abs(d$iv_coef) >= 5 * abs(d$ols_coef)
tb3[12,] <- getStat(ratio.5)
ratio.10 <- abs(d$iv_coef) >= 10 * abs(d$ols_coef)
tb3[13,] <- getStat(ratio.10)
ratio <- abs(d$iv_coef / d$ols_coef)
tb3[14,] <- getStat(ratio, method = "median")
tb3
