Hello,
I am trying to bring a program that I have written in to loops to make it easier to change the variables it is using. I am trying to get a list of odds ratio for a list of different risk factors (This form is required for another program).
So the program should loop through a list of variables, perform a logistic regression and then save the odds ratios into a variable. So far i have got really close, the first variable does exactly what i want it to, however when you add the second variable the results of the first don't seem to be saved. I was hoping someone would be able to help me retain the previous results so i have one variable that lists all of the odds ratios for all of the variables.
Here is the code i have so far:
Thanks
Cydney
I am trying to bring a program that I have written in to loops to make it easier to change the variables it is using. I am trying to get a list of odds ratio for a list of different risk factors (This form is required for another program).
So the program should loop through a list of variables, perform a logistic regression and then save the odds ratios into a variable. So far i have got really close, the first variable does exactly what i want it to, however when you add the second variable the results of the first don't seem to be saved. I was hoping someone would be able to help me retain the previous results so i have one variable that lists all of the odds ratios for all of the variables.
Here is the code i have so far:
Code:
local variables a b c gen output = . foreach var of local variables { by `var', sort: gen `var'counter = 1 if _n == 1 replace `var'counter = sum(`var'counter) local num = `var'counter[_N] foreach i of numlist 2/`num' { replace output = exp(_b[`i'.`var']) in `j++' } }
Thanks
Cydney
Comment