Re: [R] Creating a year-month indicator and groupby with category
47, 55, 50, 52, 51, 51.5, 52, 53, > 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1, > 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), row.names = c(NA, > -37L), spec = structure(list(cols = list(year = structure(list(), class = > c("collector_double", > "collector")), month = structure(list(), class = c("collector_double", > "collector")), company = structure(list(), class = c("collector_character", > "collector")), share = structure(list(), class = c("collector_double", > "collector")), com_name = structure(list(), class = c("collector_double", > "collector"))), default = structure(list(), class = c("collector_guess", > "collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df", > "tbl_df", "tbl", "data.frame")) > # convert year and month fields to dates about the middle of each month > dat$date<-as.Date(paste(dat$year,dat$month,15,sep="-"),"%Y-%m-%d") > # plot the values for one company > plot(dat$date[dat$company=="ABC"],dat$share[dat$company=="ABC"], > main="Plot of dat",xlab="Year",ylab="Share", > xlim=range(dat$date),ylim=range(dat$share), > type="l",col="red") > # add a line for the other one > > lines(dat$date[dat$company=="FGH"],dat$share[dat$company=="FGH"],col="green") > # get the x plot limits as they are date values > xspan<-par("usr")[1:2] > # place a legend about in the middle of the plot > > legend(xspan[1]+diff(xspan)*0.3,35,c("ABC","FGH"),lty=1,col=c("red","green")) > > There are many more elegant ways to plot something like this. > > Jim > > On Mon, Oct 3, 2022 at 10:05 AM Tariq Khasiri > wrote: > > > > Hello, > > > > I have the following data. I want to show in a line plot how each > different > > company is earning over the timeline of my data sample. > > > > I'm not sure how I can create the *year-month indicator* to plot it > nicely > > in my horizontal axis out of my dataset. > > > > After creating the *year-month* indicator ( which will be in my x axis) I > > want to create a dataframe where I can groupby companies over the > > year-month indicator by putting *share *in the y axis as variables. > > > > ### data is like the following > > > > dput(dat) > > structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019, > > 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, > > 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, > > 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12, > > 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, > > 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company = c("ABC", > > "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH", > > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", > > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", > > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH" > > ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55, > > 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53, > > 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1, > > 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, > > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), row.names = c(NA, > > -37L), spec = structure(list(cols = list(year = structure(list(), class = > > c("collector_double", > > "collector")), month = structure(list(), class = c("collector_double", > > "collector")), company = structure(list(), class = > c("collector_character", > > "collector")), share = structure(list(), class = c("collector_double", > > "collector")), com_name = structure(list(), class = c("collector_double", > > "collector"))), default = structure(list(), class = c("collector_guess", > > "collector")), delim = ","), class = "col_spec"), problems = > 0x7fd732028680>, class = c("spec_tbl_df", > > "tbl_df", "tbl", "data.frame")) > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@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. > [[alternative HTML version deleted]] __ R-help@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.
[R] Creating a year-month indicator and groupby with category
Hello, I have the following data. I want to show in a line plot how each different company is earning over the timeline of my data sample. I'm not sure how I can create the *year-month indicator* to plot it nicely in my horizontal axis out of my dataset. After creating the *year-month* indicator ( which will be in my x axis) I want to create a dataframe where I can groupby companies over the year-month indicator by putting *share *in the y axis as variables. ### data is like the following dput(dat) structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company = c("ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH" ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55, 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53, 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), row.names = c(NA, -37L), spec = structure(list(cols = list(year = structure(list(), class = c("collector_double", "collector")), month = structure(list(), class = c("collector_double", "collector")), company = structure(list(), class = c("collector_character", "collector")), share = structure(list(), class = c("collector_double", "collector")), com_name = structure(list(), class = c("collector_double", "collector"))), default = structure(list(), class = c("collector_guess", "collector")), delim = ","), class = "col_spec"), problems = , class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame")) [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Help with steam graph
Actually in my main data the column name is com_num ( where mistakenly I pasted the sample data here under the com_name ). So, when I run the command successfully this is the error shows up - ▆ 1. ├─... %>% sg_legend(show = TRUE, label = "Share: ") 2. ├─streamgraph::sg_legend(., show = TRUE, label = "Share: ") 3. ├─streamgraph::sg_fill_brewer(., "PuOr") 4. ├─streamgraph::sg_axis_x(., 0.8) 5. ├─streamgraph::streamgraph(., "com_num", "n", "year") 6. │ └─base::data.frame(data) 7. ├─dplyr::ungroup(.) 8. ├─dplyr::tally(., wt = share) 9. ├─dplyr::group_by(., year, com_num) 10. └─dplyr:::group_by.data.frame(., year, com_num) 11. └─dplyr::group_by_prepare(.data, ..., .add = .add, caller_env = caller_env()) 12. └─rlang::abort(bullets, call = error_call) Any suggestions on how I can fix it ?? On Sun, 2 Oct 2022 at 09:12, David Winsemius wrote: > I don’t see a column with the name ‘com_num’, so the error message makes > complete sense. > > — > David > > Sent from my iPhone > > > On Oct 2, 2022, at 5:06 AM, Tariq Khasiri > wrote: > > > > Hi, i'm trying to create a steamgraph with the following data by > creating a > > unit indicator by combing the year and month. But, I'm getting error as : > > > > Error in `group_by()`: > > ! Must group by variables found in `.data`. > > ✖ Column `com_num` is not found. > > Run `rlang::last_error()` to see where the error occurred. > > > > ### Packages needed for the code > > devtools::install_github("hrbrmstr/streamgraph") > > > > library(tidyverse) > > library(ggplot2) > > library(dplyr) > > library(steamgraph) > > > > ### Code ( The following code can be found on creator's account > > https://hrbrmstr.github.io/streamgraph/ ) > > > > dat %>% > > select(year, month, company, share, com_num) %>% > > tidyr::gather(company, share, -year) %>% > > group_by(year, com_num) %>% > > tally(wt=share) %>% > > ungroup %>% > > streamgraph("com_num", "n", "year") %>% > > sg_axis_x(0.8) %>% > > sg_fill_brewer("PuOr") %>% > > sg_legend(show=TRUE, label="Share: ") > > > > > > ### data is like the following > > > > dput(dat) > > structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019, > > 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, > > 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, > > 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12, > > 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, > > 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company = c("ABC", > > "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH", > > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", > > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", > > "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH" > > ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55, > > 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53, > > 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1, > > 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, > > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), row.names = c(NA, > > -37L), spec = structure(list(cols = list(year = structure(list(), class = > > c("collector_double", > > "collector")), month = structure(list(), class = c("collector_double", > > "collector")), company = structure(list(), class = > c("collector_character", > > "collector")), share = structure(list(), class = c("collector_double", > > "collector")), com_name = structure(list(), class = c("collector_double", > > "collector"))), default = structure(list(), class = c("collector_guess", > > "collector")), delim = ","), class = "col_spec"), problems = > 0x7fd732028680>, class = c("spec_tbl_df", > > "tbl_df", "tbl", "data.frame")) > > > >[[alternative HTML version deleted]] > > > > __ > > R-help@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. > > [[alternative HTML version deleted]] __ R-help@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.
[R] Help with steam graph
Hi, i'm trying to create a steamgraph with the following data by creating a unit indicator by combing the year and month. But, I'm getting error as : Error in `group_by()`: ! Must group by variables found in `.data`. ✖ Column `com_num` is not found. Run `rlang::last_error()` to see where the error occurred. ### Packages needed for the code devtools::install_github("hrbrmstr/streamgraph") library(tidyverse) library(ggplot2) library(dplyr) library(steamgraph) ### Code ( The following code can be found on creator's account https://hrbrmstr.github.io/streamgraph/ ) dat %>% select(year, month, company, share, com_num) %>% tidyr::gather(company, share, -year) %>% group_by(year, com_num) %>% tally(wt=share) %>% ungroup %>% streamgraph("com_num", "n", "year") %>% sg_axis_x(0.8) %>% sg_fill_brewer("PuOr") %>% sg_legend(show=TRUE, label="Share: ") ### data is like the following dput(dat) structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company = c("ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH" ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55, 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53, 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), row.names = c(NA, -37L), spec = structure(list(cols = list(year = structure(list(), class = c("collector_double", "collector")), month = structure(list(), class = c("collector_double", "collector")), company = structure(list(), class = c("collector_character", "collector")), share = structure(list(), class = c("collector_double", "collector")), com_name = structure(list(), class = c("collector_double", "collector"))), default = structure(list(), class = c("collector_guess", "collector")), delim = ","), class = "col_spec"), problems = , class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame")) [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Unable to install gsynth without life package
The R community is full of kind people! Much obliged for being so polite! On Mon, 30 May 2022 at 21:24, Jeff Newmiller wrote: > Either: > > 1) Convince the Gsynth package maintainer to resolve the problem for you, > or > > 2) start hacking on the source code of either lfe or Gsynth until they > both install and work together. > > It is not as though the members of this list have a magic wand that can > fix the problems of many thousands of _contributed_ packages. > > On May 30, 2022 9:08:04 PM PDT, Tariq Khasiri > wrote: > >Hello R Community, > > > >I'm trying to install Gsynth packaged from the instruction given on this > >website ( https://yiqingxu.org/packages/gsynth/index.html ). Out of all > the > >dependency packages lfe is removed from CRAN I believe. Therefore, I'm > >unable to install gsynth. I've looked for the solution on google but > >nothing helped so far. > > > >Any suggestion I how I can install lfe and eventually install gsynth > >successfully? All the dependency packages are given on the link above > >where the developer built the package. > > > > > >ERROR: dependency ‘lfe’ is not available for package ‘gsynth’ > >* removing > >‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/gsynth’ > >Warning in install.packages : > > installation of package ‘gsynth’ had a non-zero exit status > > > > [[alternative HTML version deleted]] > > > >__ > >R-help@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. > > -- > Sent from my phone. Please excuse my brevity. > [[alternative HTML version deleted]] __ R-help@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.
Re: [R] error as in unused argument of a new package
I took care of the issue by simply updating an already installed package. Really appreciate for the valuable feedback from R community. Glad to have such kind guidelines. On Sat, Feb 26, 2022 at 1:57 AM Ivan Krylov wrote: > On Fri, 25 Feb 2022 16:14:05 -0600 > Tariq Khasiri wrote: > > > CS_never_cond <- did::att_gt(yname="lemp", > > tname="year", > > idname="countyreal", > > gname="first.treat", > > #xformla=~1, > > xformla = xformla, > > control_group="nevertreated", > > data = min_wage, > > panel = TRUE, > > base_period="universal", # <-- here > > bstrap = TRUE, > > cband = TRUE) > > > Error in did::att_gt(yname = "lemp", tname = "year", idname = > > "countyreal", : > > unused argument (base_period = "universal") > > Does ?did::att_gt specify that the att_gt function accepts an > argument named "base_period" (marked by me with "# <-- here")? > If it does, it's a documentation error, contact maintainer('did') and > tell them about it. If it doesn't, you need to adjust your call to > did::att_gt to provide the correct arguments. > > -- > Best regards, > Ivan > [[alternative HTML version deleted]] __ R-help@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.
[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]] __ R-help@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.