I would like to count certain things in my dataset. I have panel data and ideally would like to count the number of activities per zip.
zip <- c(1,1,1,2,2,3,3,4,4,5,5)
activity <- c(1,1,1,2,2,3,4,5,5,6,6)
completion <- c(0,0,1,0,1,1,1,0,0,0,1)
So my output would tell me that person 4 has 2 tasks.
zip 1
frequency activity 2
I use this data and with this function it works perfectly.
library(dplyr)
cllw %>%
group_by(zip) %>%
summarise("id_task" = n())%>% View()
Now, i coded some dummy variables for the zip data like this:
df$California <- ifelse(df$zip ==1, 1, 0)
df$Hawaii <- ifelse(df$zip ==2, 1, 0)
df$Oregon <- ifelse(df$zip ==3, 1, 0)
df$Washington <- ifelse(df$zip ==4, 1, 0)
df$Alaska <- ifelse(df$zip ==5, 1, 0)
Now, a few days ago i just run the same code as above after adding the dummys to my df in order to not only get zip-level but state-level results.
so the output would look like this
California
frequency activity 2
How would i be able to get the state-level effects into my function