With 2+ variables, the expand approach is tricky. Use reshape instead. Otherwise, nothing else changes.
Res.:
Code:
webuse lbw, clear
* creating label for logistic regression on: 'low' odds ratios & p values
logistic low age lwt race
estimates store low
mat rtable= r(table)
mat res = (rtable["b", 1...]\rtable["pvalue", 1...])'
svmat res
drop if res1 == 0
format res1 %9.3f
gen label_low= cond(res2<0.001, string(res1,"%9.3f")+"***", ///
cond(inrange(res2, 0.001, 0.0099), string(res1,"%9.3f")+"**", ///
cond(inrange(res2, 0.01, 0.0499), string(res1,"%9.3f")+"*", string(res1,"%9.3f"))))
* creating label for logistic regression on: 'ui' odds ratios & p values
logistic ui age lwt race
mat rtable= r(table)
mat res_ui = (rtable["b", 1...]\rtable["pvalue", 1...])'
svmat res_ui
drop if res_ui1 == 0
format res_ui1 %9.3f
gen label_ui = cond(res2<0.001, string(res_ui1,"%9.3f")+"***", ///
cond(inrange(res_ui2, 0.001, 0.0099), string(res_ui1,"%9.3f")+"**", ///
cond(inrange(res_ui2, 0.01, 0.0499), string(res_ui1,"%9.3f")+"*", string(res_ui1,"%9.3f"))))
* store results for coefplot
logistic low age lwt race
estimates store low
logistic ui age lwt race
estimates store ui
logistic ht age lwt race
mat rtable=r(table)
mat res_ht = (rtable["b", 1...]\rtable["pvalue", 1...])'
svmat res_ht
drop if res_ht1 == 0
format res_ht1 %9.3f
gen label_ht = cond(res2<0.001, string(res_ht1,"%9.3f")+"***", ///
cond(inrange(res_ht2, 0.001, 0.0099), string(res_ht1,"%9.3f")+"**", ///
cond(inrange(res_ht2, 0.01, 0.0499), string(res_ht1,"%9.3f")+"*",string(res_ht1,"%9.3f" ))))
logistic ht age lwt race
estimate store ht
preserve
keep label_low label_ui label_ht
drop if label_low=="." & label_ui=="." & label_ht=="."
gen order=_n
reshape long label_@, i(order) j(which) string
gen order2= cond(which=="low", 1, cond(which=="ui", 2, 3))
sort order order2
coefplot low, mlabel(label) || ui, mlabel(label)|| ht, mlabel(label)
Comment