-------------------------------------------------------------------------------------------------------------------------------------------
help for unitab
-------------------------------------------------------------------------------------------------------------------------------------------
Univariate table
unitab depvar [varlist1] [if exp] [in range] [, level(#) format(%fmt) categorical(varlist2) exact]
Description
unitab displays a univariate table with the maximum-likelihood estimates of odds ratio and confidence intervals using logit command and
some useful information using tabulate command.
dep_var binary dependent variable that must be coded as
depvar = 0 or
depvar = # with # > 0
varlist1 covariates treated as continuous.
varlist2 covariates treated as categorical.
You can specify the same variable as continuous and/or categorical. First results are displayed for continuous variables and then for
categorical variables.
Explanation of the table
Continuous variable
1 column : summarize depvar if continuous_variable == #
2 column : total observations
3 column : point estimate of odds ratio using maximum likelihood estimators logit
4-5 columns : lower and upper bound for odds ratio at a certain level(#)
6 column : statistical significance of the odds ratio using a Wald test
Categorical variable
1 column : tabulate depvar categorical_variable (display only for depvar = # )
2 column : total observations for each category
3 column : point estimate of odds ratio using maximum likelihood estimators
4-5 columns : lower and upper bound for odds ratio at a certain level(#)
6 column : statistical significance of the Pearson's chi-squared test for the hypothesis that the rows and columns in a two-way
table are independent
Options
level(#) specifies the confidence level, in percent, for calculation of confidence intervals of the odds ratios; see help level.
format(%fmt) specifies the display format for odds ratio and confidence intervals in the univariate table. format(%4.3f) is the default;
format(%6.5f) is a popular alternative.
categorical(varlist2) specifies the variables that you want treat as categorical.
exact displays the significance calculated by Fisher's exact. We recommend specifying exact whenever samples are small.
Examples
. webuse lbw, clear
. tab low
. su age
. su age if low == 1
. logistic low age
. unitab low age
. xtile ageq = age, nq(4)
. tab ageq low, row nokey
. xi: logistic low i.ageq
. unitab low, c(ageq)
. unitab low age, c(ageq)
. tab race low, row nokey
. xi:logistic low i.race
. unitab low , c(race)
. unitab low age ht ui, c(race smoke ageq)
. unitab low age ht ui, c(race smoke ageq) l(90) f(%6.5f)
Authors
Nicola Orsini, Institute of Environmental Medicine, Karolinska Institutet, Stockholm, Sweden and Institute of Information Science and
Technology, National Research Council of Italy, Pisa, Italy.
Matteo Bottai, Arnold School of Public Health, University of South Carolina, Columbia, USA and Institute of Information Science and
Technology, National Research Council of Italy, Pisa, Italy.
Also see
[R] logistic
[R] tabulate
On-line: help for help for logistic, tabulate, summarize
Click here to run or save the do-file for the following worked examples and be sure to have an update version. Type
. capture net install http://nicolaorsini.altervista.org/stata/unitab
. which unitab
c:\ado\plus\u\unitab.ado
*! version 1.0 22 Sep 2003 N.Orsini & M.Bottai
*! version 2.0 26 Sep 2003 N.Orsini & M.Bottai
*! version 3.0 04 Apr 2004 N.Orsini & M.Bottai (only changed help file)
. webuse lbw, clear
(Hosmer & Lemeshow data)
. tab low
birth |
weight<2500 |
g | Freq. Percent Cum.
------------+-----------------------------------
0 | 130 68.78 68.78
1 | 59 31.22 100.00
------------+-----------------------------------
Total | 189 100.00
. su age
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
age | 189 23.2381 5.298678 14 45
. su age if low == 1
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
age | 59 22.30508 4.511496 14 34
. logistic low age
Logistic regression Number of obs = 189
LR chi2(1) = 2.76
Prob > chi2 = 0.0966
Log likelihood = -115.95598 Pseudo R2 = 0.0118
------------------------------------------------------------------------------
low | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
age | .9501333 .0299423 -1.62 0.105 .8932232 1.010669
------------------------------------------------------------------------------
. unitab low age
------------------------------------------------------------------------------
low | low=1(%) Total(%) OR [95% Conf. Interval] p-value
------------+-----------------------------------------------------------------
age | 59(31) 189(100) 0.950 0.893 1.011 0.105
------------------------------------------------------------------------------
. xtile ageq = age, nq(4)
. tab ageq low, row nokey chi2
4 |
quantiles | birth weight<2500g
of age | 0 1 | Total
-----------+----------------------+----------
1 | 36 15 | 51
| 70.59 29.41 | 100.00
-----------+----------------------+----------
2 | 36 20 | 56
| 64.29 35.71 | 100.00
-----------+----------------------+----------
3 | 21 15 | 36
| 58.33 41.67 | 100.00
-----------+----------------------+----------
4 | 37 9 | 46
| 80.43 19.57 | 100.00
-----------+----------------------+----------
Total | 130 59 | 189
| 68.78 31.22 | 100.00
Pearson chi2(3) = 5.3442 Pr = 0.148
. tab ageq low, row nokey exact
4 |
quantiles | birth weight<2500g
of age | 0 1 | Total
-----------+----------------------+----------
1 | 36 15 | 51
| 70.59 29.41 | 100.00
-----------+----------------------+----------
2 | 36 20 | 56
| 64.29 35.71 | 100.00
-----------+----------------------+----------
3 | 21 15 | 36
| 58.33 41.67 | 100.00
-----------+----------------------+----------
4 | 37 9 | 46
| 80.43 19.57 | 100.00
-----------+----------------------+----------
Total | 130 59 | 189
| 68.78 31.22 | 100.00
Fisher's exact = 0.143
. xi: logistic low i.ageq
i.ageq _Iageq_1-4 (naturally coded; _Iageq_1 omitted)
Logistic regression Number of obs = 189
LR chi2(3) = 5.50
Prob > chi2 = 0.1383
Log likelihood = -114.58352 Pseudo R2 = 0.0235
------------------------------------------------------------------------------
low | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Iageq_2 | 1.333333 .5533289 0.69 0.488 .5911435 3.007354
_Iageq_3 | 1.714286 .7832056 1.18 0.238 .700156 4.197316
_Iageq_4 | .5837838 .2815403 -1.12 0.264 .2268531 1.502309
------------------------------------------------------------------------------
. unitab low, c(ageq)
------------------------------------------------------------------------------
low | low=1(%) Total(%) OR [95% Conf. Interval] p-value
------------+-----------------------------------------------------------------
ageq 1 | 15(29) 51(27) . . . 0.148
2 | 20(36) 56(30) 1.333 0.591 3.007
3 | 15(42) 36(19) 1.714 0.700 4.197
4 | 9(20) 46(24) 0.584 0.227 1.502
------------------------------------------------------------------------------
. unitab low, c(ageq) exact
------------------------------------------------------------------------------
low | low=1(%) Total(%) OR [95% Conf. Interval] p-value
------------+-----------------------------------------------------------------
ageq 1 | 15(29) 51(27) . . . 0.143
2 | 20(36) 56(30) 1.333 0.591 3.007
3 | 15(42) 36(19) 1.714 0.700 4.197
4 | 9(20) 46(24) 0.584 0.227 1.502
------------------------------------------------------------------------------
. unitab low age, c(ageq)
------------------------------------------------------------------------------
low | low=1(%) Total(%) OR [95% Conf. Interval] p-value
------------+-----------------------------------------------------------------
age | 59(31) 189(100) 0.950 0.893 1.011 0.105
------------+-----------------------------------------------------------------
ageq 1 | 15(29) 51(27) . . . 0.148
2 | 20(36) 56(30) 1.333 0.591 3.007
3 | 15(42) 36(19) 1.714 0.700 4.197
4 | 9(20) 46(24) 0.584 0.227 1.502
------------------------------------------------------------------------------
. tab race low, row nokey
| birth weight<2500g
race | 0 1 | Total
-----------+----------------------+----------
white | 73 23 | 96
| 76.04 23.96 | 100.00
-----------+----------------------+----------
black | 15 11 | 26
| 57.69 42.31 | 100.00
-----------+----------------------+----------
other | 42 25 | 67
| 62.69 37.31 | 100.00
-----------+----------------------+----------
Total | 130 59 | 189
| 68.78 31.22 | 100.00
. xi:logistic low i.race
i.race _Irace_1-3 (naturally coded; _Irace_1 omitted)
Logistic regression Number of obs = 189
LR chi2(2) = 5.01
Prob > chi2 = 0.0817
Log likelihood = -114.83082 Pseudo R2 = 0.0214
------------------------------------------------------------------------------
low | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Irace_2 | 2.327536 1.078613 1.82 0.068 .9385073 5.772385
_Irace_3 | 1.889234 .6571342 1.83 0.067 .9554577 3.735597
------------------------------------------------------------------------------
. unitab low , c(race)
------------------------------------------------------------------------------
low | low=1(%) Total(%) OR [95% Conf. Interval] p-value
------------+-----------------------------------------------------------------
race 1 | 23(24) 96(51) . . . 0.082
2 | 11(42) 26(14) 2.328 0.939 5.772
3 | 25(37) 67(35) 1.889 0.955 3.736
------------------------------------------------------------------------------
. unitab low age ht ui, c(race smoke ageq)
------------------------------------------------------------------------------
low | low=1(%) Total(%) OR [95% Conf. Interval] p-value
------------+-----------------------------------------------------------------
age | 59(31) 189(100) 0.950 0.893 1.011 0.105
------------+-----------------------------------------------------------------
ht | 59(31) 189(100) 3.365 1.021 11.088 0.046
------------+-----------------------------------------------------------------
ui | 59(31) 189(100) 2.578 1.139 5.834 0.023
------------+-----------------------------------------------------------------
race 1 | 23(24) 96(51) . . . 0.082
2 | 11(42) 26(14) 2.328 0.939 5.772
3 | 25(37) 67(35) 1.889 0.955 3.736
------------+-----------------------------------------------------------------
smoke 0 | 29(25) 115(61) . . . 0.026
1 | 30(41) 74(39) 2.022 1.081 3.783
------------+-----------------------------------------------------------------
ageq 1 | 15(29) 51(27) . . . 0.148
2 | 20(36) 56(30) 1.333 0.591 3.007
3 | 15(42) 36(19) 1.714 0.700 4.197
4 | 9(20) 46(24) 0.584 0.227 1.502
------------------------------------------------------------------------------
. unitab low age ht ui, c(race smoke ageq) l(90) f(%6.5f)
------------------------------------------------------------------------------
low | low=1(%) Total(%) OR [90% Conf. Interval] p-value
------------+-----------------------------------------------------------------
age | 59(31) 189(100) 0.95013 0.90214 1.00068 0.105
------------+-----------------------------------------------------------------
ht | 59(31) 189(100) 3.36538 1.23726 9.15396 0.046
------------+-----------------------------------------------------------------
ui | 59(31) 189(100) 2.57778 1.29874 5.11644 0.023
------------+-----------------------------------------------------------------
race 1 | 23(24) 96(51) . . . 0.082
2 | 11(42) 26(14) 2.32754 1.08607 4.98812
3 | 25(37) 67(35) 1.88923 1.06614 3.34780
------------+-----------------------------------------------------------------
smoke 0 | 29(25) 115(61) . . . 0.026
1 | 30(41) 74(39) 2.02194 1.19518 3.42061
------------+-----------------------------------------------------------------
ageq 1 | 15(29) 51(27) . . . 0.148
2 | 20(36) 56(30) 1.33333 0.67373 2.63871
3 | 15(42) 36(19) 1.71429 0.80857 3.63453
4 | 9(20) 46(24) 0.58378 0.26408 1.29051
------------------------------------------------------------------------------