iam working on a data with repeated same variable prefix, i want to perform calculations on the varible and mutate new variable based on some conditions, this is my stata codes how can i do this in R

sort patid

foreach var of varlist issuedate_n*{

by patid: egen presc_var'=count(var') if `var'<admidate_n

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?

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".

Thank you for your response.
My problem is I have svereal coumn for issuedate_n each ends with different number ranging from (1_515) and I want to check at one go and create a new variable if condition met. I cant just write issuedate_n because I have several number of columns