install.packages('nloptr')
library(nloptr)
install.packages('Rcpp')
install.packages('RcppEigen')
install.packages('cem')
sessionInfo()
library(devtools)
devtools::install_github("xuyiqing/hbal@88fa2f6d520ca00ec5a45062b30388fccda13ca6")
library(devtools)
devtools::install_github("xuyiqing/hbal@88fa2f6d520ca00ec5a45062b30388fccda13ca6")
devtools::install_github("xuyiqing/hbal@88fa2f6d520ca00ec5a45062b30388fccda13ca6")
library(ggplot2)
library(tidyverse)
library(data.table)
a <- fread('/Users/eddie/Desktop/category_for/dimensions_author_v4.csv')
a$pre_collab <- a$ChinaCollab2010 + a$ChinaCollab2011 + a$ChinaCollab2012 + a$ChinaCollab2013 + a$ChinaCollab2014
a$other_collab <- a$OtherCollab2010 + a$OtherCollab2011 + a$OtherCollab2012 + a$OtherCollab2013 + a$OtherCollab2014
a$pp_collab <- a$ChinaCollab2015 + a$ChinaCollab2016 + a$ChinaCollab2017 + a$ChinaCollab2018
a$pre_total <- a$PublicationNumber2010 + a$PublicationNumber2011 + a$PublicationNumber2012 + a$PublicationNumber2013 + a$PublicationNumber2014
a$pre_pb <- a$PubMed2010 + a$PubMed2011 + a$PubMed2012 + a$PubMed2013 + a$PubMed2014
a$pre_top <- a$Top100_2010 + a$Top100_2011 + a$Top100_2012 + a$Top100_2013 + a$Top100_2014
a$pre_cite <- a$TotalCitation2010 + a$TotalCitation2011 + a$TotalCitation2012 + a$TotalCitation2013 + a$TotalCitation2014
a$pp_nih <- a$NIH2010 + a$NIH2011 + a$NIH2012 + a$NIH2013 +  a$NIH2014
a$treat <- NA
a$treat[a$pre_collab > 0] <- 1 # 2010-2014 US-China collaboration > 0
a$treat[a$pre_collab == 0 & a$pp_collab==0 &a$other_collab>0] <- 0 # 2010-2018 US-China collaboration = 0
a <- a[!is.na(a$treat),]
set.seed(92092)
auth <- sample(a$author_researcher_id, 100, replace = FALSE)
b <- fread('/Users/eddie/Downloads/DataForEddie.csv')
colnames(b)[9] <- 'link'
b <- b[b$year>=2010 & b$year<=2020,]
c <- b %>%
group_by(Name, year) %>%
summarise(cite = sum(citeCount))
pub <- b %>%
group_by(Name) %>%
mutate(totalpub=n()) %>%
slice(1) %>%
select(Name, totalpub)
d <- expand_grid(name = unique(c$Name), year = 2010:2020)
e <- left_join(d, c, by=c('name'='Name', 'year'='year'))
e$cite[is.na(e$cite)] <- 0
e <- b %>%
distinct(Name, link) %>%
select(Name, link) %>%
right_join(e, by=c('Name'='name'))
e <- left_join(e, pub, by=c('Name'))
f <- fread('/Users/eddie/Downloads/dimensions_sample.csv')
colnames(f)[6] <- 'link'
g <- fread('/Users/eddie/Documents/ChinaScience/dimensions_sample_authors.csv')
f$author_researcher_id <- auth
f[,1:2] <- g[,1:2]
f <- f %>%
inner_join(e, by='link')
length(unique(f$Name))
ff <- f %>%
group_by(Name) %>%
slice(1)
p1 <- ggplot(ff, aes(x=log(`Total Publications`+1), y=log(totalpub+1))) + geom_point() +
geom_abline(intercept = 0, slope = 1, size = 0.5, lty='longdash') +
xlim(1.7, 6) + ylim(1.7, 6) + theme_bw() +
labs(x='Log Publications on Google Scholar', y='Log Publications on Dimensions')
cor(ff$`Total Publications`, ff$totalpub)
?ggsave
ggsave('/Users/eddie/Documents/ChinaScience/validation_pub.png', p1)
a <- fread('/Users/eddie/Desktop/category_for/dimensions_author_v4.csv')
a <- a %>%
select(c(starts_with('TotalCitation'), author_researcher_id)) %>%
pivot_longer(cols = starts_with("TotalCitation", ignore.case = FALSE),
names_prefix = "TotalCitation", names_to = "year", values_to = "citations")
a$year <- as.numeric(a$year)
colnames(f)[1:2] <- c('author_first_name', 'author_last_name')
fff <- left_join(f, a, by=c('author_researcher_id', 'year'))
p2 <- ggplot(fff, aes(x=log(cite+1), y=log(citations+1))) + geom_point() +
geom_abline(intercept = 0, slope = 1, size = 0.5, lty='longdash') +
theme_bw() + labs(x='Log Citations on Google Scholar', y='Log Citations on Dimensions')
cor(fff$citations, fff$cite)
ggsave('/Users/eddie/Documents/ChinaScience/validation_cite.png', p2)
p1 <- ggplot(ff, aes(x=log(`Total Publications`+1), y=log(totalpub+1))) + geom_point() +
geom_abline(intercept = 0, slope = 1, size = 0.5, lty='longdash') +
xlim(1.7, 6) + ylim(1.7, 6) + theme_bw() +
labs(x='Log Publications on Google Scholar', y='Log Publications on Dimensions') +
ggtitle(paste0('Correlation = ', round(cor(ff$`Total Publications`, ff$totalpub), 1)))
p1
p1 <- ggplot(ff, aes(x=log(`Total Publications`+1), y=log(totalpub+1))) + geom_point() +
geom_abline(intercept = 0, slope = 1, size = 0.5, lty='longdash') +
xlim(1.7, 6) + ylim(1.7, 6) + theme_bw() +
labs(x='Log Publications on Google Scholar', y='Log Publications on Dimensions') +
ggtitle(paste0('Correlation = ', round(cor(ff$`Total Publications`, ff$totalpub), 2)))
ggsave('/Users/eddie/Documents/ChinaScience/validation_pub.png', p1)
ggsave('/Users/eddie/Documents/ChinaScience/validation_pub.png', p1, 7, 7)
?ggsave
ggsave('/Users/eddie/Documents/ChinaScience/validation_pub.png', p1, width = 7, height = 7)
library(hbal)
library(hbal)
library(hbal)
library(hbal)
library(hbal)
library(hbal)
library(hbal)
library(hbal)
library(hbal)
library(Rcpp)
library(hbal)
library(hbal)
library(hbal)
sessionInfo()
library(devtools)
install_github('xuyiqing/hbal')
library(hbal)
library(hbal)
library(tidyverse)
library(hbal)
set.seed(92092)
N <- 500
X1 <- rnorm(N)
X2 <- rbinom(N,size=1,prob=.5)
X <- cbind(X1, X2) # Covariates
treat <- rbinom(N, 1, prob=0.5) # Treatment indicator
y <- X[,1] + X[,2] + rnorm(N) # Outcome
?hbal
out <- hbal(Treatment = treat, X = X,  Y = y)
tidy(hbal::att(out))
library(broom)
tidy(hbal::att(out))
plot(out)
out$penalty
library(ggplot2)
library(tidyverse)
library(data.table)
a <- fread('/Users/eddie/Desktop/category_for/dimensions_author_v4.csv')
a$pre_collab <- a$ChinaCollab2010 + a$ChinaCollab2011 + a$ChinaCollab2012 + a$ChinaCollab2013 + a$ChinaCollab2014
a$other_collab <- a$OtherCollab2010 + a$OtherCollab2011 + a$OtherCollab2012 + a$OtherCollab2013 + a$OtherCollab2014
a$pp_collab <- a$ChinaCollab2015 + a$ChinaCollab2016 + a$ChinaCollab2017 + a$ChinaCollab2018
a$pre_total <- a$PublicationNumber2010 + a$PublicationNumber2011 + a$PublicationNumber2012 + a$PublicationNumber2013 + a$PublicationNumber2014
a$pre_pb <- a$PubMed2010 + a$PubMed2011 + a$PubMed2012 + a$PubMed2013 + a$PubMed2014
a$pre_top <- a$Top100_2010 + a$Top100_2011 + a$Top100_2012 + a$Top100_2013 + a$Top100_2014
a$pre_cite <- a$TotalCitation2010 + a$TotalCitation2011 + a$TotalCitation2012 + a$TotalCitation2013 + a$TotalCitation2014
a$pp_nih <- a$NIH2010 + a$NIH2011 + a$NIH2012 + a$NIH2013 +  a$NIH2014
a$treat <- NA
a$treat[a$pre_collab > 0] <- 1 # 2010-2014 US-China collaboration > 0
a$treat[a$pre_collab == 0 & a$pp_collab==0 &a$other_collab>0] <- 0 # 2010-2018 US-China collaboration = 0
a <- a[!is.na(a$treat),]
set.seed(92092)
auth <- sample(a$author_researcher_id, 100, replace = FALSE)
b <- fread('/Users/eddie/Downloads/DataForEddie.csv')
colnames(b)[9] <- 'link'
b <- b[b$year>=2010 & b$year<=2020,]
c <- b %>%
group_by(Name, year) %>%
summarise(cite = sum(citeCount))
pub <- b %>%
group_by(Name) %>%
mutate(totalpub=n()) %>%
slice(1) %>%
select(Name, totalpub)
d <- expand_grid(name = unique(c$Name), year = 2010:2020)
e <- left_join(d, c, by=c('name'='Name', 'year'='year'))
e$cite[is.na(e$cite)] <- 0
e <- b %>%
distinct(Name, link) %>%
select(Name, link) %>%
right_join(e, by=c('Name'='name'))
e <- left_join(e, pub, by=c('Name'))
f <- fread('/Users/eddie/Downloads/dimensions_sample.csv')
colnames(f)[6] <- 'link'
g <- fread('/Users/eddie/Documents/ChinaScience/dimensions_sample_authors.csv')
f$author_researcher_id <- auth
f[,1:2] <- g[,1:2]
f <- f %>%
inner_join(e, by='link')
length(unique(f$Name))
ff <- f %>%
group_by(Name) %>%
slice(1)
p1 <- ggplot(ff, aes(x=log(`Total Publications`+1), y=log(totalpub+1))) + geom_point() +
geom_abline(intercept = 0, slope = 1, size = 0.5, lty='longdash') +
xlim(1.7, 6) + ylim(1.7, 6) + theme_bw() +
labs(x='Log Publications on Google Scholar', y='Log Publications on Dimensions') +
ggtitle(paste0('Correlation = ', round(cor(ff$`Total Publications`, ff$totalpub), 2)))
ggsave('/Users/eddie/Documents/ChinaScience/validation_pub.png', p1, width = 7, height = 7)
a <- fread('/Users/eddie/Desktop/category_for/dimensions_author_v4.csv')
a <- a %>%
select(c(starts_with('TotalCitation'), author_researcher_id)) %>%
pivot_longer(cols = starts_with("TotalCitation", ignore.case = FALSE),
names_prefix = "TotalCitation", names_to = "year", values_to = "citations")
a$year <- as.numeric(a$year)
colnames(f)[1:2] <- c('author_first_name', 'author_last_name')
fff <- left_join(f, a, by=c('author_researcher_id', 'year'))
p2 <- ggplot(fff, aes(x=log(cite+1), y=log(citations+1))) + geom_point() +
geom_abline(intercept = 0, slope = 1, size = 0.5, lty='longdash') +
theme_bw() + labs(x='Log Citations on Google Scholar', y='Log Citations on Dimensions') +
ggtitle(paste0('Correlation = ', round(cor(ff$citations, ff$cite), 2)))
p2 <- ggplot(fff, aes(x=log(cite+1), y=log(citations+1))) + geom_point() +
geom_abline(intercept = 0, slope = 1, size = 0.5, lty='longdash') +
theme_bw() + labs(x='Log Citations on Google Scholar', y='Log Citations on Dimensions') +
ggtitle(paste0('Correlation = ', round(cor(fff$citations, fff$cite), 2)))
p2
ggsave('/Users/eddie/Documents/ChinaScience/validation_cite.png', p2, width = 7, height = 7)
?qq
?qqnorm
setwd('/Users/eddie/Dropbox/ebal2/replication/')
b1 <- read.csv('Appendix/Output/bootstrap_1.csv')
boot1 <- scale(b1[,1])
fw1 <- scale(b1[,2])
b2 <- read.csv('Appendix/Output/bootstrap_3.csv')
boot2 <- scale(b2[,1])
fw2 <- scale(b2[,2])
b3 <- read.csv('Appendix/Output/bootstrap_5.csv')
boot3 <- scale(b3[,1])
fw3 <- scale(b3[,2])
j1 <- read.csv('Appendix/Output/jackknife_1.csv')
jack1 <- scale(j1[,1])
j2 <- read.csv('Appendix/Output/jackknife_3.csv')
jack2 <- scale(j2[,1])
j3 <- read.csv('Appendix/Output/jackknife_5.csv')
jack3 <- scale(j3[,1])
qqnorm(fw1, main = "Fixed Weights, C:T = 1",
xlab = "Theoretical Quantiles", ylab = "Sample")
qqnorm(fw1, main = "Fixed Weights, C:T = 1",
xlab = "Theoretical Quantiles", ylab = "Sample",
xlim=c(-3, 3), ylim=(-3, 3))
qqnorm(fw1, main = "Fixed Weights, C:T = 1",
xlab = "Theoretical Quantiles", ylab = "Sample",
xlim=c(-3, 3), ylim=c(-3, 3))
png(filename="Appendix/Output/qq.png", width=2048, height=2048, res=200)
par(mar=c(5.1, 5, 4.1, 2.1), mfrow=c(3,3))
qqnorm(fw1, main = "Fixed Weights, C:T = 1",
xlab = "Theoretical Quantiles", ylab = "Sample",
xlim=c(-3, 3), ylim=c(-3, 3))
qqline(fw1, lty=2)
qqnorm(boot1, main = "Bootstrap, C:T = 1",
xlab = "Theoretical Quantiles", ylab = "Sample",
xlim=c(-3, 3), ylim=c(-3, 3))
qqline(boot1, lty=2)
qqnorm(jack1, main = "Jackknife, C:T = 1",
xlab = "Theoretical Quantiles", ylab = "Sample",
xlim=c(-3, 3), ylim=c(-3, 3))
qqline(jack1, lty=2)
qqnorm(fw2, main = "Fixed Weights, C:T = 3",
xlab = "Theoretical Quantiles", ylab = "Sample",
xlim=c(-3, 3), ylim=c(-3, 3))
qqline(fw2, lty=2)
qqnorm(boot2, main = "Bootstrap, C:T = 3",
xlab = "Theoretical Quantiles", ylab = "Sample",
xlim=c(-3, 3), ylim=c(-3, 3))
qqline(boot2, lty=2)
qqnorm(jack2, main = "Jackknife, C:T = 3",
xlab = "Theoretical Quantiles", ylab = "Sample",
xlim=c(-3, 3), ylim=c(-3, 3))
qqline(jack2, lty=2)
qqnorm(fw3, main = "Fixed Weights, C:T = 5",
xlab = "Theoretical Quantiles", ylab = "Sample",
xlim=c(-3, 3), ylim=c(-3, 3))
qqline(fw3, lty=2)
qqnorm(boot3, main = "Bootstrap, C:T = 5",
xlab = "Theoretical Quantiles", ylab = "Sample",
xlim=c(-3, 3), ylim=c(-3, 3))
qqline(boot3, lty=2)
qqnorm(jack3, main = "Jackknife, C:T = 5",
xlab = "Theoretical Quantiles", ylab = "Sample",
xlim=c(-3, 3), ylim=c(-3, 3))
qqline(jack3, lty=2)
dev.off()
?qqline
