I have been referring to this question :R Optimal way to create time series from start and end dates for groups because I am trying to do the same thing with my data. I was not trying both methods at the same time, I tested both out separately. I get small errors when trying either solution. Any help would be greatly appreciated! My final dataset is going to be very large so I am more interested in solution 1.
Packages and working code
library(AER) library(sandwich) library(car) library(stargazer) library(ggplot2) library(standardize) library(tidyverse) library(dplyr) library(lubridate) library(data.table) #date format is mm/dd/yy csuite <- read.csv("boardex_new.csv", header=TRUE, sep=",") #I want to make the results of these lines into a new df csuite %>% #selects the columns in a specific order select("CompanyID", "Ticker", "RoleName", "DateStartRole", "DateEndRole", "DirectorName", "DirectorID") %>% # Filters the RoleName column as specified below filter(RoleName == "VP/COO" | RoleName == "CEO" | RoleName == "COO" | RoleName == "VP/CFO")
range <- rbindlist(lapply(genDataRange(dat$startdate, dat$enddate, dat$id),as.data.frame)) Error in genDataRange(csuite$DateStartRole, csuite$DateEndRole) : could not find function "genDataRange"
csuite <- data.table(csuite) csuite[,`:=`(DateStartRole = as.Date(DateStartRole, DateEndRole = as.Date(DateEndRole))] csuite[,num_mons:= length(seq(from=040196, to=072121, by='month')),by=1:nrow(csuite)] Error: unexpected ']' in "csuite[,`:=`(DateStartRole = as.Date(DateStartRole, DateEndRole = as.Date(DateEndRole))]" Error in del/by : non-numeric argument to binary operator