I have the panel data and I am applying propensity score matching. I have estimated the model on full sample using the following codes in CBPS package.
form1 <- (treat ~ X)
fit <- CBPS(formula=form1, data = paper1, time=year, id= bankid, ATT = TRUE)
I want to match now separately for the each year. I am using the if condition for this purpose and I have run the following code.
if (year==2001){
m.out1 <- matchit(t1 ~ fitted(fit), method = "nearest", data = paper1, replace = TRUE)
}
However, following warning is generated.
Warning message: In if (year == 2001) { : the condition has length > 1 and only the first element will be used
How I can perform the desired task?
I have replicated the problem with Blackwell data set. The complete codes are provided below: – There is a time id in the data set. I want to match if the time is equal to 1. I have run the model on full sample though.
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)
}