I have several dataframes (with different names) like those below, with the same number of rows and columns but different names for the last column.
df1:
ID matching_variable STATUS code_1
1 1 1 1
2 1 0 1
3 2 1 0
4 2 1 0
df2:
ID matching_variable STATUS code_2
1 1 1 1
2 1 0 0
3 2 1 0
4 2 1 1
I have about a dozen df's like this and I would like to do a logistic regression of this style for each df:
fit1<-clogit(STATUS~code_1+strata(matching_variable),data=df1)
fit2<-clogit(STATUS~code_2+strata(matching_variable),data=df2)
etc….
I would like to make a function to "automate" this (without having to write all the regressions) and have all the outputs of the regressions in a new table.
I thought of using something like this function: (but as I have different names for the df and for the last column, I get stuck...)
list<-list(df1,df2)
results<- lapply(list, function(x) {clogit(STATUS ~ code_??? + strata(matching_variable), data=???, l)})
Thank you in advance.