我有面板数据,我正在申请倾向得分匹配。我已经使用CBPS软件包中的以下代码对完整样本进行了模型估计。
form1 <- (treat ~ X)
fit <- CBPS(formula=form1, data = paper1, time=year, id= bankid, ATT = TRUE)我想每年都分开比赛。为此,我将使用if条件,并运行了以下代码。
if (year==2001){
m.out1 <- matchit(t1 ~ fitted(fit), method = "nearest", data = paper1, replace = TRUE)
}但是,将生成以下警告。
警告消息:在if (年份== 2001)中,{:条件的长度>1,并且只使用第一个元素
我怎样才能完成想要的任务?
我已经复制了Blackwell数据集的问题。完整的代码如下所示:-数据集中有一个时间id。我想要匹配,如果时间是等于1。我已经运行了模型的充分样本。
library(CBPS)
data("Blackwell")
attach(Blackwell)
form1<-"d.gone.neg ~ d.gone.neg.l1 + d.gone.neg.l2 + d.neg.frac.l3 + camp.length + camp.length + deminc + base.poll + year.2002 + year.2004 + year.2006 + base.und + office"
fit <- CBPS(formula=form1, data = Blackwell, time=time, id= demName, ATT = TRUE)
m.out <- matchit(d.gone.neg ~ fitted(fit), method = "nearest", data = Blackwell, replace = TRUE)
summary(m.out)
if (time==1){
m.out1 <- matchit(d.gone.neg ~ fitted(fit), method = "nearest", data = Blackwell, replace = TRUE)
}发布于 2016-06-13 17:16:23
if (!require("pacman")) install.packages("pacman")
pacman::p_load(CBPS, RRF)
data("Blackwell")
attach(Blackwell)
Blackwell$year <- NA
Blackwell$year[Blackwell$year.2002 == 1] <- 2002
Blackwell$year[Blackwell$year.2004 == 1] <- 2004
Blackwell$year[Blackwell$year.2006 == 1] <- 2006
Blackwell$year.2002 <- NULL
Blackwell$year.2004 <- NULL
Blackwell$year.2006 <- NULL
Blackwell <- na.roughfix(Blackwell)
form1<-"d.gone.neg ~ d.gone.neg.l1 + d.gone.neg.l2 + d.neg.frac.l3 + camp.length + camp.length + deminc + base.poll + year.2002 + year.2004 + year.2006 + base.und + office"
fit <- CBPS(formula=form1, data = Blackwell, time=time, id= demName, ATT = TRUE)
m.out <- matchit(d.gone.neg ~ fitted(fit), method = "nearest", data = Blackwell, replace = TRUE)
summary(m.out)
m.out1 <- list()
n <- 0
for(i in unique(Blackwell$year)){
n <- n+1
tmp <- matchit(d.gone.neg ~ fitted(fit)[Blackwell$year == i], method = "nearest", data = Blackwell[Blackwell$year == i,], replace = TRUE)
nam <- paste("matchit_", i, sep = "")
assign(nam, tmp)
}发布于 2016-06-12 20:04:56
我已经复制了Blackwell数据集的问题。完整的代码如下所示:-数据集中有一个时间id。我想要匹配,如果时间是等于1。我已经运行了模型的充分样本。
library(CBPS)
data("Blackwell")
attach(Blackwell)
form1<-"d.gone.neg ~ d.gone.neg.l1 + d.gone.neg.l2 + d.neg.frac.l3 + camp.length + camp.length + deminc + base.poll + year.2002 + year.2004 + year.2006 + base.und + office"
fit <- CBPS(formula=form1, data = Blackwell, time=time, id= demName, ATT = TRUE)
m.out <- matchit(d.gone.neg ~ fitted(fit), method = "nearest", data = Blackwell, replace = TRUE)
summary(m.out)
if (time==1){
m.out1 <- matchit(d.gone.neg ~ fitted(fit), method = "nearest", data = Blackwell, replace = TRUE)
}警告消息:在if (time == 1) {:条件的长度>1,并且只使用第一个元素
https://stackoverflow.com/questions/37770903
复制相似问题