Dear Statalisters,
I am trying to automate the process of creating a table using Stata 15. I want to extract odds ratios for multiple regressions and list them in a table, including the labels of the values. Currently this is what I've got:
This returns:
What I would like is a third column which extracts the value label of the variable, like so:
I have tried another line of code, but it doesn't extract the odds ratios properly:
This returns:
As you can see, the values for smoker are incorrect.
I have also tried installing elabel, but my institution won't let me install it. Any advice would be greatly appreciated.
I am trying to automate the process of creating a table using Stata 15. I want to extract odds ratios for multiple regressions and list them in a table, including the labels of the values. Currently this is what I've got:
Code:
webuse lbw, clear foreach var in smoke race { qui { logistic low i.`var' matrix _or = r(table) levelsof `var' scalar _count = r(r) } forval x = 1/`=_count' { if `var' == smoke & `x' == 1 { di "Variable" _col(15) "Odds Ratio" } di "`var'" _col(15) _or[1,`x'] } }
Code:
Variable Odds Ratio smoke 1 smoke 2.0219436 race 1 race 2.3275362 race 1.8892339
Code:
Variable Level Odds Ratio smoke non-smoker 1 smoke smoker 2.0219436 race white 1 race black 2.3275362 race other 1.8892339
I have tried another line of code, but it doesn't extract the odds ratios properly:
Code:
foreach var in smoke race { qui logistic low i.`var' matrix _or = r(table) qui levelsof `var', local(levels) local vlname: value label `var' foreach L of local levels { local vl: label `vlname' `L' display "`vl'" _col(15) _or[1,`L'] } }
Code:
nonsmoker . smoker 1 white 1 black 2.3275362 other 1.8892339
I have also tried installing elabel, but my institution won't let me install it. Any advice would be greatly appreciated.
Comment