I am trying to write a macro that can repeat over many independent variables. The dependent variable, outcome, is the same. I don't want to type independent variables over and over again. For example, I have variable age and gender, and I want to use it in my regression.
However, I am getting errors.
Here is my function:
lapply(c("age", "gender"),
       function (var) {
         formula <- as.formula(paste("cov1 =", var))
         shr_fit <-
           crr(
             ftime = followuptime,
             fstatus = followupstatus,
             formula, # this is where I want to apply the macro #
             cencode = 0,
             failcode = 1,
             data=data1
           )
         summary(shr_fit)
       }
)
