Tariq Khasiri
2021-Jun-25 18:54 UTC
[R] Error in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm)
Just trying to replicate the Callaway and Sant'Anna average treatment group effect for my research where I would like to see how a particular law implementation is affecting all the treated states' wages compared to the never treated states' ( control group ) wage : ## Cleaning treated and never treated dat$treat = ifelse(is.na(dat$law_effective_year),0,1) dat$nevertreated = ifelse(dat$treat==0,1,0) ## Command for CSDID out1 <- att_gt(yname="ln_incwage", tname="year", gname="law_effective_year", xformla=~male + age + age2 + age3 + age4 + black + asian + hispanic + lths + hsdegree + somecollege , data=dat, est_method = "dr", # "dr" is doubly robust. "ipw" is inverse probability weighting. "reg" is regression control_group = "nevertreated", # set the comparison group which is either "nevertreated" or "notyettreated" print_details = FALSE, # if TRUE, print detailed results clustervars = "statefip", # cluster level panel = FALSE) # wh) summary(out1) But the error I'm getting is - Error in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm na.rm) : Calling var(x) on a factor x is defunct. Use something like 'all(duplicated(x)[-1L])' to test for a constant vector. Can anyone tell me what's the issue ? [[alternative HTML version deleted]]
Duncan Murdoch
2021-Jun-26 08:45 UTC
[R] Error in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm)
This is a duplicate of your SO post: https://stackoverflow.com/questions/68135737/error-in-varif-is-vectorx-is-factorx-x-else-as-doublex There you were asked for some data to make it reproducible. You shouldn't assume that people here are any more clairvoyant than the SO readers. Duncan Murdoch On 25/06/2021 2:54 p.m., Tariq Khasiri wrote:> Just trying to replicate the Callaway and Sant'Anna average treatment > group effect for my research where I would like to see how a particular law > implementation is affecting all the treated states' wages compared to the > never treated states' ( control group ) wage : > > ## Cleaning treated and never treated > > dat$treat = ifelse(is.na(dat$law_effective_year),0,1) > > dat$nevertreated = ifelse(dat$treat==0,1,0) > > ## Command for CSDID > > out1 <- att_gt(yname="ln_incwage", > tname="year", > gname="law_effective_year", > xformla=~male + age + age2 + age3 + age4 + black + asian + > hispanic + lths + hsdegree + somecollege , > data=dat, > est_method = "dr", # "dr" is doubly robust. "ipw" is inverse > probability weighting. "reg" is regression > control_group = "nevertreated", # set the comparison group > which is either "nevertreated" or "notyettreated" > print_details = FALSE, # if TRUE, print detailed results > clustervars = "statefip", # cluster level > panel = FALSE) # wh) > > summary(out1) > > But the error I'm getting is - > > Error in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm > na.rm) : > Calling var(x) on a factor x is defunct. > Use something like 'all(duplicated(x)[-1L])' to test for a constant > vector. > > Can anyone tell me what's the issue ? > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Rolf Turner
2021-Jun-26 11:37 UTC
[R] Error in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm)
On Fri, 25 Jun 2021 13:54:44 -0500 Tariq Khasiri <tariqkhasiri at gmail.com> wrote:> Just trying to replicate the Callaway and Sant'Anna average treatment > group effect for my research where I would like to see how a > particular law implementation is affecting all the treated states' > wages compared to the never treated states' ( control group ) wage : > > ## Cleaning treated and never treated > > dat$treat = ifelse(is.na(dat$law_effective_year),0,1) > > dat$nevertreated = ifelse(dat$treat==0,1,0) > > ## Command for CSDID > > out1 <- att_gt(yname="ln_incwage", > tname="year", > gname="law_effective_year", > xformla=~male + age + age2 + age3 + age4 + black + > asian + hispanic + lths + hsdegree + somecollege , > data=dat, > est_method = "dr", # "dr" is doubly robust. "ipw" is > inverse probability weighting. "reg" is regression > control_group = "nevertreated", # set the comparison > group which is either "nevertreated" or "notyettreated" > print_details = FALSE, # if TRUE, print detailed > results clustervars = "statefip", # cluster level > panel = FALSE) # wh) > > summary(out1) > > But the error I'm getting is - > > Error in var(if (is.vector(x) || is.factor(x)) x else as.double(x), > na.rm = na.rm) : > Calling var(x) on a factor x is defunct. > Use something like 'all(duplicated(x)[-1L])' to test for a constant > vector. > > Can anyone tell me what's the issue ? > > [[alternative HTML version deleted]](1) Please don't post in html. (Read the posting guide.) (2) Where does the function att_gt() come from? It's not in base R so it is presumably from a contributed package. Don't expect your readers/helpers to be telepathic. (3) Given that it's from a contributed package, you should in the first instance contact the maintainer of the package rather than this list. Only if you get no response from the maintainer should you appeal to the list. You can find the email address of the maintainer by typing maintainer(<package name>). (4) From the error message I would guess that there is a bug in the package; it apparently uses defunct syntax in that it tries to apply var() to factors. It seems that this used to be allowed, but is no longer. But that's just a guess; I know nothing about what att_gt() is designed to do. Good luck. cheers, Rolf Turner -- Honorary Research Fellow Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276