I'm learning how to do a propensity analysis, my reprex works but when I replicate the same exact code with the real data, I get the following error
rr1 <- Match(Y = Y, Tr = Tr, X = proptest001$fitted)
Error in Match(Y = Y, Tr = Tr, X = proptest001$fitted) :
length(Tr) != nrow(X)
Here is the reprex
library(Matching)
#> Warning: package 'Matching' was built under R version 3.6.3
#> Loading required package: MASS
#> ##
#> ## Matching (Version 4.9-7, Build Date: 2020-02-05)
#> ## See http://sekhon.berkeley.edu/matching for additional documentation.
#> ## Please cite software as:
#> ## Jasjeet S. Sekhon. 2011. ``Multivariate and Propensity Score Matching
#> ## Software with Automated Balance Optimization: The Matching package for R.''
#> ## Journal of Statistical Software, 42(7): 1-52.
#> ##
datapasta::df_paste(head(corc002, 5)[, c('positive', 'arb', 'aarace')])
#> Error in head(corc002, 5): object 'corc002' not found
#so you can see where the data for DF comes from
DF<-data.frame(
positive = c(1, 1, 1, 1, 1),
arb = c(0, 0, 1, 0, 0),
aarace = c(0, 0, 1, 0, 0)
)
DF
#> positive arb aarace
#> 1 1 0 0
#> 2 1 0 0
#> 3 1 1 1
#> 4 1 0 0
#> 5 1 0 0
Tr<-cbind(DF$arb)
Y<-cbind(DF$positive)
X<-cbind(DF$aarace)
glm1 <- glm(Tr ~ X, family=binomial(link = "probit"), data=DF)
rr1 <- Match(Y = Y, Tr = Tr, X = glm1$fitted)
summary(rr1)
#>
#> Estimate... 0
#> AI SE...... 0
#> T-stat..... NaN
#> p.val...... NA
#>
#> Original number of observations.............. 5
#> Original number of treated obs............... 1
#> Matched number of observations............... 1
#> Matched number of observations (unweighted). 4
Here is the code I used
Y<cbind(corc002$positive)
Y<-cbind(corc002$positive)
Tr<-cbind(corc002$arb)
X<-cbind(corc002$aarace)
proptest001 <- glm(Tr ~ X, family=binomial(link = "probit"), data=corc002)
summary(proptest001)
rr1 <- Match(Y = Y, Tr = Tr, X = proptest001$fitted)
What gives? I'm still a noob so I'm sure I'm making a dumb mistake but I've spent hours on this and can only scream four letter expletives at my computer for so long.