Time to procedure/event

I am currently working on online database called national inpatient sample using R studio. I have procedure code called I10_PR1 to PR25. Then I have another called PRD1 to PRD 9 which tells the specific day the specific procedure is being performed. Day 0 is the day of admission and day 1 the next day and so on. . I want to create a dummy variable first based on if the procedure is performed which I will write as below:

**mydata$procedure = apply(new, 1, function(row){
  ifelse("procedure code " %in% row, 1, 0)

but I am having trouble in creating the time to that specific procedure. Could someone help with the correct code for that ? In Stata I would write something like this:
generate procedure=.
foreach var of numlist 1/15 {
replace timetoprocedure=PRDAYvar' if PRvar' == "5491"
} but I need the equivalent in R.
Thank you Zafar

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.