The idea is to get the count of observations of the variable "variable" for each "country" and "year" to compute some standard errors and some nice confidence intervals. I believe in the code above I'm getting the count of all observations in a country in a specific year, but because "variable" has some NA it isn't what I need for the computation of SE and CI. If it clarifies further my question: I think the n() above isn't using the same figure as the one used by mean(), the one I need.
I've tried add_count() to no avail. What would you suggest? Thanks!
Are you looking for the count of value that different that NA ? N = sum(!is.na(variable)) could be what you want.
otherwise, you could use the wt in tally, %>% add_tally(wt = !is.na(variable)
@cderv Thanks for your reply. I was so focused on n() that I didn't think of looking up sum(). Just to learn how to use add_tally(), could you elaborate how/where it fits in the code below instead of sum()? Thanks a lot!
If your question's been answered would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: