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 PR
var' == "5491"
} but I need the equivalent in R.
Thank you Zafar