how can I solve "Error in lowest:highest : argument of length 0" for synthetic control method of basque ?

Hi, and welcome. A reproducible example, called a reprex helps to attract more answers. Your code is almost complete. It should look like this

library(Synth)
#> ##
#> ## Synth Package: Implements Synthetic Control Methods.
#> ## See http://www.mit.edu/~jhainm/software.htm for additional information.
data(basque)
dataprep.out <- dataprep(
   foo = basque,
   predictors = c("school.illit","school.prim","school.med","school.high","school.post.high","invest"),
   predictors.op = "mean",
   time.predictors.prior = 1964:1969,
   special.predictors = list(
     list("gdpcap", 1960:1969, "mean"),
     list("sec.agriculture", seq(1961, 1969, 2), "mean"),
     list("sec.energy", seq(1961, 1969, 2), "mean"),
     list("sec.industry", seq(1961, 1969, 2), "mean"),
     list("sec.construction", seq(1961, 1969, 2), "mean"),
     list("sec.services.venta", seq(1961, 1969, 2), "mean"),
     list("sec.services.nonventa", seq(1961, 1969, 2), "mean"),
     list("popdens", 1969, "mean")),
   dependent = "gdpcap",
   unit.variable = "regionno",
   unit.names.variable = "regionname",
   time.variable = "year",
   treatment.identifier = 17,
   controls.identifier = c(2:16, 18),
   time.optimize.ssr = 1960:1969,
   time.plot = 1955:1997)

dataprep.out$X1["school.high",] <- dataprep.out$X1["school.high",] + dataprep.out$X1["school.post.high",]
dataprep.out$X1 <- as.matrix(dataprep.out$X1[which(rownames(dataprep.out$X1) == "school.post.high"),])
dataprep.out$X0["school.high",] <- dataprep.out$X0["school.high",] + dataprep.out$X0["school.post.high",]
dataprep.out$X0 <- dataprep.out$X0[which(rownames(dataprep.out$X0) == "school.post.high"),]
lowest <- which(rownames(dataprep.out$X0) == "school.illit")
highest <- which(rownames(dataprep.out$X0) == "school.high")
dataprep.out$X1[lowest:highest,] <- (100 * dataprep.out$X1[lowest:highest,]) / sum(dataprep.out$X1[lowest:highest,])
#> Error in lowest:highest: argument of length 0
dataprep.out$X1[lowest:highest,] <- (100 * dataprep.out$X1[lowest:highest,])/sum(dataprep.out$X1[lowest:highest,])
#> Error in lowest:highest: argument of length 0

Created on 2019-10-14 by the reprex package (v0.3.0)

The errors arise from

dataprep.out$X1
      [,1]
[1,] 13.48

which is a single element matrix. So, if you subset it, the result is always going to be

dataprep.out$X1[lowest]
numeric(0)

except for cases like dataprep.out$X1[1,1]

I can't tell from your code what it is that you're trying to calculate specifically.

1 Like