I'm not sure what the stata code is, but I'm assuming that you have a dataframe called 'Patid' and that you are creating a running count if issuedate_n is greater than admidate_n?
Maybe this code would be helpful:
library(tidyverse)
patid %>%
mutate(presc_var = if_else(issuedate_n < admidate_n, 1, 0)) %>%
mutate(presc_var_running_count = sumsum(presc_var))
It's read:
"Use the datatable 'patid',
then,
make or change the variable 'presc_var' by placing a one if the condition is true or or zero if false,
then,
make or change the variable 'presc_var_running_count' by running a cumulative summation of whatever is now in presc_var".