0

I am getting an error that is stating "(subscript) logical subscript too long. Traceback: median(permsamples2.91[business2.91$yrqtr == "20201", i]).

I am attempting to do a permutation test that looks at the difference in median wages between 2019Q1 and 2020Q1. Below is a sample of my code and some of the details wit it.

business2.91<-rbind(business.20122.27, business.20122.31)
set.seed(20204)
p<-100000
n2.91<-length(business2.91)
variable2.91<-business2.91$wage.adjusted
permsamples2.91<- matrix(0,nrow=n2.91, ncol=p)
for(i in 1:p){
  permsamples2.91[,i] <- sample(variable2.91, size= n2.91, replace=FALSE)
}

perm.test.stat2.91<-rep(0,p)

for (i in 1:p){
  # calculate the perm-test-stat2 and save it
  perm.test.stat2.91[i] <- abs( median(permsamples2.91[business2.91$yrqtr=='20201',i]) - 
                               median(permsamples2.91[business2.91$yrqtr=="20191",i]) )
}

For business.2.91 there are 617 rows that have 20201 as their yrqtr while 20191 has 582 rows. Is the discrepancy is rows the issue?

  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. If you do subsetting like `permsamples2.91[business2.91$yrqtr=='20201',i]` the `nrow(permsamples2.91)` must equal `nrow(business2.91)`. And that doesn't sound like that's true in your case. It's not clear exactly what you are trying to accomplish. – MrFlick Jan 30 '23 at 21:58

0 Answers0