Dear all,
I am trying to conduct a series of logistic regressions, of the form:
There are a lot of sites so I want to use loops to automate, something like this:
My problem is that I need to include different independent variables in the model; depending on which site I am looking at (this order was determined from a previous exercise identifying best-fitting models associated with break-points in a continuous variable which vary with site).
I feel there must be a way for Stata to lookup the necessary code from a table or similar to do this. If the relevant table looked like this:
the final models would be:
I would like to use loops to automate this in the form:
glm outcome age "column2" "column3" if site =="column1", family(binom)
I feel there must be a way to do this, storing the whole table as a macro and then drawing the relevant cells into my model.
I am using Stata 15.0: and thank you very much for any guidance.
Josh.
I am trying to conduct a series of logistic regressions, of the form:
Code:
glm outcome age var1a var1b if site ==1, family(binom)
Code:
levelsof site foreach g in `r(levels)' { glm outcome age var1a var1b if site ==`g', family(binom) }
I feel there must be a way for Stata to lookup the necessary code from a table or similar to do this. If the relevant table looked like this:
site | v1 | v2 |
1 | var1a | var2a |
2 | var1b | var2b |
3 | var2a | var2b |
Code:
glm outcome age var1a var2a if site ==1, family(binom) glm outcome age var1b var2b if site ==2, family(binom) glm outcome age var2a var2b if site ==3, family(binom)
glm outcome age "column2" "column3" if site =="column1", family(binom)
I feel there must be a way to do this, storing the whole table as a macro and then drawing the relevant cells into my model.
I am using Stata 15.0: and thank you very much for any guidance.
Josh.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double outcome float(age var1a var1b var2a var2b site) 1 16.5 2 14.4 3 13.4 1 1 12.5 2 10.9 3 9.9 1 1 10.5 2 8.6 3 7.6 1 1 14.5 2 12.7 3 11.7 1 1 14.5 2 12.5 3 11.5 1 1 13.5 2 11.4 3 10.4 1 1 13.5 2 11.2 3 10.2 1 0 12.5 2 10.1 3 9.1 1 1 14.5 2 12.7 3 11.7 1 1 12.5 2 10.1 3 9.1 2 1 13.5 2 11.7 3 10.7 2 0 12.5 2 10.1 3 9.1 2 0 11.5 2 9.9 3 8.9 2 1 11.5 2 9.6 3 8.6 2 1 14.5 2 12.9 3 11.9 2 0 14.5 2 12.9 3 11.9 3 1 11.5 2 9.9 3 8.9 3 0 11.5 2 9.8 3 8.8 3 1 13.5 2 11.4 3 10.4 3 1 14.5 2 12.2 3 11.2 3 0 12.5 2 10.8 3 9.8 3 end
Comment