Hi,
I am having issues using -collect- to make a table of regression coefficients especially when an independent variable is continuous.
Here are three options I have tried but each is unsatisfactory to me, as noted in the comment.
I also could not get the desired table with the Tables Builder.
It would look like,
Thanks,
Scott
I am having issues using -collect- to make a table of regression coefficients especially when an independent variable is continuous.
Here are three options I have tried but each is unsatisfactory to me, as noted in the comment.
Code:
. clear all
. set obs 1000
Number of observations (_N) was 0, now 1,000.
. gen x=runiformint(0,1)
. label var x "Outcome"
. gen c = runiform()
. lab var c "Continuous"
. gen i = runiformint(1,3)
. label var i "Discrete"
. cap collect drop c1
. collect create c1
(current collection is c1)
. collect OR=_r_b P=_r_p _r_ci,name(c1) : ///
> logistic x c.c i.i
Logistic regression Number of obs = 1,000
LR chi2(3) = 1.43
Prob > chi2 = 0.6974
Log likelihood = -692.03768 Pseudo R2 = 0.0010
------------------------------------------------------------------------------
x | Odds ratio Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
c | 1.289403 .2840073 1.15 0.249 .8373382 1.985531
|
i |
2 | 1.033049 .1635239 0.21 0.837 .757499 1.408834
3 | 1.042367 .1573393 0.27 0.783 .7754193 1.401214
|
_cons | .9074241 .1386773 -0.64 0.525 .6725511 1.224321
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.
. est store e
.
. collect dims //no dim for c?
Collection dimensions
Collection: c1
-----------------------------------------
Dimension No. levels
-----------------------------------------
Layout, style, header, label
cmdset 1
coleq 1
colname 9
colname_remainder 1
i 3
program_class 2
result 46
result_type 3
rowname 1
Style only
border_block 4
cell_type 4
-----------------------------------------
.
. collect style header, level(label) title(label)
. collect style row stack ,spacer
. collect style cell result, nformat(%4.2f)
. collect style cell _r_ci, cidelimiter(",") sformat("(%s)")
. //option 1
. collect layout (c i)(result[OR _r_ci]) // ?? does not show c at all ??
(dimension c not found)
Collection: c1
Rows: c i
Columns: result[OR _r_ci]
Table 1: 4 x 2
-----------------------------
| Result Result
| OR 95% CI
---------+-------------------
Discrete |
1 | 1.00
2 | 1.03 (0.76,1.41)
3 | 1.04 (0.78,1.40)
-----------------------------
.
. //option 2
. collect layout (colname)(result[OR _r_ci]) // ?? does not show var label for discrete ??
Collection: c1
Rows: colname
Columns: result[OR _r_ci]
Table 1: 8 x 2
-----------------------------------------------------
| Result Result
| OR 95% CI
---------------------------------+-------------------
Covariate names and column names |
Continuous | 1.29 (0.84,1.99)
|
Discrete=1 | 1.00
Discrete=2 | 1.03 (0.76,1.41)
Discrete=3 | 1.04 (0.78,1.40)
|
Intercept | 0.91 (0.67,1.22)
-----------------------------------------------------
.
. //option 3 ?? cannot get CI next to OR instead of below??
. etable , estimates(e) cstat(_r_b, label("OR") nformat("%03.2f")) cstat(_r_ci, label("95%CI
> ") cidelimiter(",") sformat("(%s)") nformat("%03.2f"))
----------------------------------
x
----------------------------------
Continuous 1.29
(0.84,1.99)
Discrete
2 1.03
(0.76,1.41)
3 1.04
(0.78,1.40)
Intercept 0.91
(0.67,1.22)
Number of observations 1000
----------------------------------
It would look like,
Code:
-----------------------------
| Result Result
| OR 95% CI
---------+-------------------
Continuous | 1.29 (0.84, 1.99)
Discrete |
1 | 1.00
2 | 1.03 (0.76,1.41)
3 | 1.04 (0.78,1.40)
-----------------------
Thanks,
Scott

Comment