Fitting Regression Models in Stata by Outcome Type: Syntax and What Each Coefficient Means

On this page
อ่านฉบับภาษาไทย (Thai version)
Abstract
This article fits one regression model for each type of outcome on one synthetic cohort of 1,200 adults admitted with pneumonia, 327 of them with diabetes. For every model it gives the Stata command, the one output line to read, and one sentence that says the coefficient in clinical words. Length of stay gives a difference in means of 1.44 days. ICU admission gives three numbers from one table, then an odds ratio of 1.65 from logit. After the log-binomial model fails to converge, modified Poisson gives a risk ratio of 1.41, and the identity link gives a risk difference of 0.094. Severity gives a cumulative odds ratio of 1.90 and discharge destination gives relative risk ratios; margins turns both into predicted probabilities. Readmissions give incidence rate ratios, with exposure() for rates. Death gives a hazard ratio of 1.92 after stset, and vce(cluster hospital) changes only the standard error.
One cohort, seven outcomes
Take one cohort of 1,200 adults admitted to hospital with pneumonia: 327 have diabetes and 873 do not. The question never changes. How different is a patient with diabetes from one without it, at the same age and sex?
What changes is the outcome. The same patients are measured seven ways: length of stay, ICU admission, severity grade, discharge destination, number of readmissions, readmissions per person-year (the number of readmissions divided by the years each patient was followed), and time to death within 365 days. Each outcome needs its own command, and each command prints a different kind of number.
Every model below adjusts for c.age and i.female. In Stata, the c in c.age tells the command that age is a continuous number, and the i in i.female that female is a category, so each category other than the base gets its own row in the output. The cohort is simulated by a do-file, so no real patient is in it.
Diabetes enters the same way, as i.diabetes, so the line to read is the row Yes under diabetes. Three places differ and say so when they come: the crude two-by-two table has no adjustment, mlogit has one Yes row per destination, and margins gives one Yes row per predicted category.
This is the second of three posts. First you choose the model: Which Regression Model? A Decision Flow from Study Design and Outcome (Y) to the Stata Command. Then you fit it, which is this post. Then you check that it can be believed: Checking a Regression Model: Assumptions, Diagnostics and What to Do When They Fail.
Length of stay: a difference in means
Length of stay is counted in days. regress fits a straight line, so its coefficient is in days too: the difference in mean stay between patients with and without diabetes of the same age and sex.
Stata prints 1.436325 (95% CI 1.160553 to 1.712098). In clinical words: at the same age and sex, patients with diabetes stay about 1.44 days longer on average. Checks of the straight line and its residuals belong to regress alone, and they live in Checking a Regression Model: Assumptions, Diagnostics and What to Do When They Fail.
* ---- 2. Continuous Y (length of stay): linear regression ----
* b for diabetes = difference in mean length of stay (days), same age and sex.
* b ของเบาหวาน = ผลต่างของค่าเฉลี่ยวันนอน (วัน) ที่อายุและเพศเดียวกัน
regress los i.diabetes c.age i.female
estimates store model_los_regress
* line to read: Diabetes Yes, Coefficient [95% conf. interval]
. regress los i.diabetes c.age i.female
Source | SS df MS Number of obs = 1,200
-------------+---------------------------------- F(3, 1196) = 100.02
Model | 1390.25663 3 463.418878 Prob > F = 0.0000
Residual | 5541.19262 1,196 4.6331042 R-squared = 0.2006
-------------+---------------------------------- Adj R-squared = 0.1986
Total | 6931.44926 1,199 5.78102523 Root MSE = 2.1525
------------------------------------------------------------------------------
los | Coefficient Std. err. t P>|t| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | 1.436325 .1405606 10.22 0.000 1.160553 1.712098
age | .0655404 .0052618 12.46 0.000 .055217 .0758638
|
female |
Female | -.3359886 .1253015 -2.68 0.007 -.5818238 -.0901535
_cons | 2.696336 .3631627 7.42 0.000 1.983829 3.408843
------------------------------------------------------------------------------
ICU admission: three numbers from one table
ICU admission is yes or no. Before any model, put the 1,200 patients in a two-by-two table. Of the 327 patients with diabetes, 112 went to ICU; of the 873 without diabetes, 197 did.
That one table gives three numbers, each answering a different question. The risk difference asks how many more patients in every hundred. The risk ratio asks how many times the risk. The odds ratio asks how many times the odds, where the odds are ICU patients divided by patients who stayed on the ward.
The three measures by hand
With diabetes, 112 went to ICU and 215 did not; without diabetes, 197 did and 676 did not.
-
Step 1. Risk with diabetes
112 / 327 = 0.3425
-
Step 2. Risk without diabetes
197 / 873 = 0.2257
-
Step 3. Risk difference
0.3425 minus 0.2257 = 0.1168, about 11.7 more ICU admissions in every 100 patients.
-
Step 4. Risk ratio
0.3425 / 0.2257 = 1.52, so about 1.52 times the risk.
-
Step 5. Odds ratio
The odds are 112 / 215 = 0.5209 with diabetes and 197 / 676 = 0.2914 without; 0.5209 / 0.2914 = 1.79.
Result: Stata's cs command prints the same three numbers: risk difference .116849, risk ratio 1.517813 and odds ratio 1.787558.
* ---- 3. Binary Y (ICU admission): the crude 2x2 table first ----
* One table gives all three measures: risk difference, risk ratio and odds ratio.
* ตารางเดียวให้ครบสามตัววัด: risk difference, risk ratio และ odds ratio
tabulate icu diabetes, column
cs icu diabetes, or
* lines to read: Risk difference, Risk ratio, Odds ratio (crude, no adjustment)
. tabulate icu diabetes, column
+-------------------+
| Key |
|-------------------|
| frequency |
| column percentage |
+-------------------+
ICU | Diabetes (exposure)
admission | No Yes | Total
-----------+----------------------+----------
No | 676 215 | 891
| 77.43 65.75 | 74.25
-----------+----------------------+----------
Yes | 197 112 | 309
| 22.57 34.25 | 25.75
-----------+----------------------+----------
Total | 873 327 | 1,200
| 100.00 100.00 | 100.00
. cs icu diabetes, or
| Diabetes [exposure] |
| Exposed Unexposed | Total
-----------------+------------------------+-----------
Cases | 112 197 | 309
Noncases | 215 676 | 891
-----------------+------------------------+-----------
Total | 327 873 | 1200
| |
Risk | .3425076 .2256586 | .2575
| |
| Point estimate | [95% conf. interval]
|------------------------+------------------------
Risk difference | .116849 | .0584161 .1752819
Risk ratio | 1.517813 | 1.250112 1.842841
Attr. frac. ex. | .3411573 | .2000714 .4573595
Attr. frac. pop | .1236557 |
Odds ratio | 1.787558 | 1.354116 2.359829 (Cornfield)
+-------------------------------------------------
chi2(1) = 16.99 Pr>chi2 = 0.0000
Odds ratio: logit with the or option
Logit fits its coefficient b on the log of the odds, so for diabetes it first gets b = 0.4989. That number is hard to read, so the or option converts it back with exp(0.4989) = 1.6469, which is the odds ratio. This is why the column reads Odds ratio.
Stata prints 1.646897 (95% CI 1.239519 to 2.188162). The interval does not include 1, the value that would mean no difference, so the odds are higher with diabetes. In clinical words: at the same age and sex, patients with diabetes have about 1.65 times the odds of ICU admission, against a crude 1.79.
The odds ratio is valid at any prevalence. In case-control data logistic regression is still the model, and Stata prints an odds ratio. What that odds ratio estimates in the cohort (an odds ratio, a risk ratio or a rate ratio) depends on how the controls were sampled; see Control Sampling in Stata: Question, Controls and Model Are Three Different Things.
* ---- 4. Binary Y, measure = odds ratio: logistic regression ----
* exp(b) = odds ratio of ICU admission, diabetes vs no diabetes.
* exp(b) = odds ratio ของการเข้า ICU ผู้ป่วยเบาหวานเทียบกับไม่เป็นเบาหวาน
logit icu i.diabetes c.age i.female, or
estimates store model_icu_logit
* line to read: Diabetes Yes, Odds ratio [95% conf. interval]
. logit icu i.diabetes c.age i.female, or
Iteration 0: Log likelihood = -684.51086
Iteration 1: Log likelihood = -655.55088
Iteration 2: Log likelihood = -655.09143
Iteration 3: Log likelihood = -655.09116
Iteration 4: Log likelihood = -655.09116
Logistic regression Number of obs = 1,200
LR chi2(3) = 58.84
Prob > chi2 = 0.0000
Log likelihood = -655.09116 Pseudo R2 = 0.0430
------------------------------------------------------------------------------
icu | Odds ratio Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | 1.646897 .2387784 3.44 0.001 1.239519 2.188162
age | 1.03403 .0061759 5.60 0.000 1.021996 1.046206
|
female |
Female | .636516 .0885237 -3.25 0.001 .4846499 .8359696
_cons | .0356252 .0151098 -7.86 0.000 .0155144 .0818048
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.
Risk ratio: try log-binomial first, and see when it fails
A risk ratio comes from a binomial model with a log link. The family names the kind of outcome, here yes or no. The link names the scale on which the covariates add up, here the log of the risk, so exp(b) is a risk ratio. Family and link are taught in full in Link and Family: One Picks Your Effect Measure, the Other Your Standard Error.
A risk must stay below 1, but with a common outcome the log link can push some predicted risks above 1. The fit then fails to converge: the search for the best estimates stops before it finds them. Stata does not stop with an error; it prints a table anyway.
Three signs show the failure. The line convergence not achieved sits above the table, the standard errors on the Yes row are dots, and the footer says Warning: Convergence not achieved. Then display e(converged) prints 0 instead of 1, so the number on that row is not a result.
* ---- 5. Binary Y, measure = risk ratio: log-binomial GLM, then modified Poisson ----
* Log-binomial first. If it fails (no convergence), the failure is shown and the run goes on.
* nolog hides up to 300 iteration lines; the table footer still prints "Convergence not achieved".
* Watch out: Stata does NOT stop with an error here. Read the footer and e(converged) (1 = yes).
* ลอง log-binomial ก่อน ถ้าไม่ converge จะแสดงให้เห็นแล้วรันต่อ nolog ซ่อนบรรทัด iteration
* ระวัง: Stata ไม่หยุดด้วย error ต้องอ่านท้ายตารางและ e(converged) (1 = converge)
capture noisily glm icu i.diabetes c.age i.female, family(binomial) link(log) eform nolog
local return_code_log_binomial = _rc
display as text "log-binomial GLM: return code = `return_code_log_binomial' (0 = it ran)"
if `return_code_log_binomial' == 0 display as text "log-binomial GLM: e(converged) = " e(converged)
* line to read (only if e(converged) = 1): Diabetes Yes, Risk ratio [95% conf. interval]
* In this cohort it does NOT converge (Stata also warns of inadmissible mean estimates, i.e. a fitted
* risk above 1 for some patients), so the risk ratio is read from the next model.
. capture noisily glm icu i.diabetes c.age i.female, family(binomial) link(log)
> eform nolog
convergence not achieved
Generalized linear models Number of obs = 1,200
Optimization : ML Residual df = 1,199
Scale parameter = 1
Deviance = 1652.086292 (1/df) Deviance = 1.377887
Pearson = 100001576.4 (1/df) Pearson = 83404.15
Variance function: V(u) = u*(1-u) [Bernoulli]
Link function : g(u) = ln(u) [Log]
AIC = 1.378405
Log likelihood = -826.0431461 BIC = -6848.916
------------------------------------------------------------------------------
| OIM
icu | Risk ratio std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | 1.224657 . . . . .
age | 1.014894 1.03e-10 1.5e+08 0.000 1.014894 1.014894
|
female |
Female | .3517312 .029269 -12.56 0.000 .2987988 .4140406
_cons | .2067673 . . . . .
------------------------------------------------------------------------------
Note: _cons estimates baseline risk.
Warning: Parameter estimates produce inadmissible mean estimates in one or
more observations.
Warning: Convergence not achieved.
. local return_code_log_binomial = _rc
. display as text "log-binomial GLM: return code = `return_code_log_binomial' (
> 0 = it ran)"
log-binomial GLM: return code = 0 (0 = it ran)
. if `return_code_log_binomial' == 0 display as text "log-binomial GLM: e(conve
> rged) = " e(converged)
log-binomial GLM: e(converged) = 0
Risk ratio: modified Poisson
When log-binomial fails, fit a Poisson model with a log link, even though the outcome is yes or no. That model is only a working tool: it gives the right risk ratio, but its usual standard error is wrong for a yes-or-no outcome. So ask Stata for a robust standard error, vce(robust), one that does not trust the Poisson variance formula. This combination is called modified Poisson regression, and it is not log-binomial.
Stata labels the column IRR, but for a yes-or-no outcome it is a risk ratio: 1.413388 (95% CI 1.166529 to 1.712487). In clinical words: at the same age and sex, patients with diabetes have about 1.41 times the risk of ICU admission.
The adjusted odds ratio, 1.65, sits well above this 1.41. With 25.75% of patients going to ICU, an odds ratio read as a risk ratio overstates the effect. Risk ratios for a common outcome are taught in Getting a Risk Ratio for a Common Outcome: The Step-Down When Log-Binomial Hits the Wall.
* Modified Poisson: a Poisson working model with a robust variance (NOT log-binomial).
* It is the fallback when log-binomial fails; it is shown always so the two can be compared.
* modified Poisson คือ Poisson working model กับ robust variance (ไม่ใช่ log-binomial)
glm icu i.diabetes c.age i.female, family(poisson) link(log) vce(robust) eform
estimates store model_icu_modified_poisson
* line to read: Diabetes Yes, IRR column = risk ratio here [95% conf. interval]
. glm icu i.diabetes c.age i.female, family(poisson) link(log) vce(robust) efor
> m
Iteration 0: Log pseudolikelihood = -722.66696
Iteration 1: Log pseudolikelihood = -706.88398
Iteration 2: Log pseudolikelihood = -706.87128
Iteration 3: Log pseudolikelihood = -706.87128
Generalized linear models Number of obs = 1,200
Optimization : ML Residual df = 1,196
Scale parameter = 1
Deviance = 795.7425607 (1/df) Deviance = .6653366
Pearson = 886.4595257 (1/df) Pearson = .7411869
Variance function: V(u) = u [Poisson]
Link function : g(u) = ln(u) [Log]
AIC = 1.184785
Log pseudolikelihood = -706.8712804 BIC = -7683.989
------------------------------------------------------------------------------
| Robust
icu | IRR std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | 1.413388 .138426 3.53 0.000 1.166529 1.712487
age | 1.024199 .0040683 6.02 0.000 1.016257 1.032204
|
female |
Female | .7234893 .0732169 -3.20 0.001 .5933225 .882213
_cons | .0496235 .0144917 -10.28 0.000 .0279968 .0879562
------------------------------------------------------------------------------
Note: _cons estimates baseline incidence rate.
Risk difference: the identity link
A risk difference comes from a binomial model with an identity link. The identity link adds the covariates on the risk itself, so the coefficient is a difference in risk, written as a proportion.
This model converged, so e(converged) is 1, and it printed .0937788 (95% CI .0352486 to .152309). In clinical words: at the same age and sex, about 9.4 more patients in every 100 with diabetes go to ICU (95% CI 3.5 to 15.2 per 100).
If the identity link fails, use the linear probability model: regress on the 0 or 1 outcome with vce(robust). It gives .0971603 here, close to the binomial answer.
* ---- 6. Binary Y, measure = risk difference: identity-link binomial GLM, then LPM ----
* Identity-binomial first. If it fails, the error is shown and the run goes on.
* ลอง binomial identity link ก่อน ถ้าไม่ converge จะแสดง error แล้วรันต่อ
capture noisily glm icu i.diabetes c.age i.female, family(binomial) link(identity)
local return_code_identity_binomial = _rc
display as text "identity-binomial GLM: return code = `return_code_identity_binomial' (0 = it ran)"
if `return_code_identity_binomial' == 0 display as text "identity-binomial GLM: e(converged) = " e(converged)
* line to read (only if e(converged) = 1): Diabetes Yes, Coefficient = risk difference (proportion) [95% CI]
* Linear probability model with robust SE: the fallback for the risk difference, shown always.
* linear probability model กับ robust SE เป็นทางสำรองของ risk difference แสดงทุกครั้ง
regress icu i.diabetes c.age i.female, vce(robust)
estimates store model_icu_linear_prob
* line to read: Diabetes Yes, Coefficient = risk difference (proportion) [95% CI]
------------------------------------------------------------------------------
| OIM
icu | Coefficient std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | .0937788 .0298629 3.14 0.002 .0352486 .152309
age | .0056011 .0008977 6.24 0.000 .0038416 .0073607
|
female |
Female | -.0693855 .0238538 -2.91 0.004 -.1161381 -.0226329
_cons | -.1171567 .0612593 -1.91 0.056 -.2372226 .0029093
------------------------------------------------------------------------------
Coefficients are the risk differences.
. local return_code_identity_binomial = _rc
. display as text "identity-binomial GLM: return code = `return_code_identity_b
> inomial' (0 = it ran)"
identity-binomial GLM: return code = 0 (0 = it ran)
. if `return_code_identity_binomial' == 0 display as text "identity-binomial GL
> M: e(converged) = " e(converged)
identity-binomial GLM: e(converged) = 1
. * line to read (only if e(converged) = 1): Diabetes Yes, Coefficient = risk d
> ifference (proportion) [95% CI]
.
. * Linear probability model with robust SE: the fallback for the risk differen
> ce, shown always.
. * linear probability model กับ robust SE เป็นทางสำรองของ risk difference แสดง
> ทุกครั้ง
. regress icu i.diabetes c.age i.female, vce(robust)
Linear regression Number of obs = 1,200
F(3, 1196) = 20.90
Prob > F = 0.0000
R-squared = 0.0480
Root MSE = .42736
------------------------------------------------------------------------------
| Robust
icu | Coefficient std. err. t P>|t| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | .0971603 .0295794 3.28 0.001 .039127 .1551935
age | .0059742 .0009909 6.03 0.000 .0040301 .0079184
|
female |
Female | -.0814194 .0246059 -3.31 0.001 -.129695 -.0331438
_cons | -.1392389 .0658511 -2.11 0.035 -.2684354 -.0100424
------------------------------------------------------------------------------
Severity grade: a cumulative odds ratio
Severity has three ordered grades: mild (0), moderate (1) and severe (2). The scale can be cut in two places: moderate or severe against mild, and severe against mild or moderate.
ologit fits both cuts at once and assumes that diabetes multiplies the odds by the same factor at each cut: the odds of being moderate or severe rather than mild, and the odds of being severe rather than moderate or mild, both rise by that one factor. That shared factor is the cumulative odds ratio. Stata writes the model as logit P(Y > k) = xb minus cut_k, where xb is the part that depends on diabetes, age and sex, and cut_k is the threshold for cut k.
Stata prints 1.898396 (95% CI 1.490758 to 2.417501). In clinical words: at the same age and sex, patients with diabetes have about 1.90 times the odds of a worse grade, at either cut. The rows /cut1 (2.638261) and /cut2 (4.161577) are thresholds between grades, not effects.
P(Y > k) means a worse grade only because a higher code is a worse grade here, so recode an outcome that runs the other way. Ordinal and multinomial models are compared in full in Multinomial vs Ordinal Logistic Regression [mlogit & ologit]: Choosing the Right Model for Categorical Outcomes.
* ---- 7. Ordered Y (severity): ordinal logistic regression ----
* exp(b) = cumulative odds ratio: odds of a higher grade vs that grade or lower, same at every split.
* exp(b) = cumulative odds ratio: odds ของระดับที่สูงกว่าเทียบกับระดับนั้นหรือต่ำกว่า เท่ากันทุกจุดตัด
ologit severity i.diabetes c.age i.female, or
estimates store model_severity_ologit
* line to read: Diabetes Yes, Odds ratio [95% CI]; /cut1 and /cut2 are thresholds, not effects
. ologit severity i.diabetes c.age i.female, or
Iteration 0: Log likelihood = -1202.5936
Iteration 1: Log likelihood = -1160.4847
Iteration 2: Log likelihood = -1160.281
Iteration 3: Log likelihood = -1160.281
Ordered logistic regression Number of obs = 1,200
LR chi2(3) = 84.63
Prob > chi2 = 0.0000
Log likelihood = -1160.281 Pseudo R2 = 0.0352
------------------------------------------------------------------------------
severity | Odds ratio Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | 1.898396 .2341316 5.20 0.000 1.490758 2.417501
age | 1.03446 .0051357 6.82 0.000 1.024443 1.044575
|
female |
Female | 1.081509 .122423 0.69 0.489 .8663174 1.350153
-------------+----------------------------------------------------------------
/cut1 | 2.638261 .3472221 1.957719 3.318804
/cut2 | 4.161577 .3599673 3.456054 4.8671
------------------------------------------------------------------------------
Note: Estimates are transformed only in the first equation to odds ratios.
What the cumulative odds ratio means for patients: margins
A cumulative odds ratio of 1.90 is hard to say at the bedside; predicted probabilities are easier. After ologit, the margins command sets every patient to no diabetes, then to diabetes. It keeps each patient's own age and sex and averages the predicted probability of each grade over the 1,200 patients.
Read the rows in pairs. Mild (1#) is .5720471 without diabetes and .4190982 with it. Moderate (2#) is .2822321 and .3391309, and severe (3#) is .1457208 and .241771.
In clinical words: with diabetes, the share predicted to be mild falls from 57.2% to 41.9%, and the share predicted to be severe rises from 14.6% to 24.2%.
* Predicted probability of each grade, diabetes No vs Yes (age and sex as observed).
* ความน่าจะเป็นของแต่ละระดับ เบาหวาน No เทียบ Yes (อายุและเพศตามข้อมูลจริง)
margins diabetes, predict(outcome(0)) predict(outcome(1)) predict(outcome(2))
* lines to read: _predict 1 = Mild, 2 = Moderate, 3 = Severe; each row No / Yes
. margins diabetes, predict(outcome(0)) predict(outcome(1)) predict(outcome(2))
Predictive margins Number of obs = 1,200
Model VCE: OIM
1._predict: Pr(severity==0), predict(outcome(0))
2._predict: Pr(severity==1), predict(outcome(1))
3._predict: Pr(severity==2), predict(outcome(2))
------------------------------------------------------------------------------
| Delta-method
| Margin std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
_predict#|
diabetes |
1#No | .5720471 .016309 35.08 0.000 .5400821 .6040121
1#Yes | .4190982 .025041 16.74 0.000 .3700187 .4681777
2#No | .2822321 .0131492 21.46 0.000 .2564601 .308004
2#Yes | .3391309 .0158437 21.40 0.000 .3080778 .3701839
3#No | .1457208 .0108448 13.44 0.000 .1244654 .1669762
3#Yes | .241771 .0198377 12.19 0.000 .2028897 .2806522
------------------------------------------------------------------------------
Two separate logits beside the one ologit
The single 1.90 assumes both cuts share one odds ratio. A quick look is to fit each cut as its own logit. Moderate or severe against mild gives 2.049064, severe against the rest gives 1.650193, and 1.90 sits between them. How far apart they may drift is a model check, in Checking a Regression Model: Assumptions, Diagnostics and What to Do When They Fail.
* The two splits as separate logits: the single ologit OR should sit near both.
* แยกเป็น logit สองตัวตามจุดตัด OR เดียวของ ologit ควรอยู่ใกล้ทั้งสองค่า
generate severity_above_mild = severity >= 1 if !missing(severity) // moderate or severe vs mild
generate severity_above_moderate = severity == 2 if !missing(severity) // severe vs mild or moderate
label variable severity_above_mild "Severity moderate or severe (Y > 0)"
label variable severity_above_moderate "Severity severe (Y > 1)"
logit severity_above_mild i.diabetes c.age i.female, or
estimates store model_severity_split_1
* line to read: Diabetes Yes, Odds ratio for Y > 0
logit severity_above_moderate i.diabetes c.age i.female, or
estimates store model_severity_split_2
* line to read: Diabetes Yes, Odds ratio for Y > 1
------------------------------------------------------------------------------
severity_a~d | Odds ratio Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | 2.049064 .2775216 5.30 0.000 1.571341 2.672027
age | 1.036067 .0054689 6.71 0.000 1.025403 1.046841
|
female |
Female | 1.094906 .1322875 0.75 0.453 .8640399 1.387457
_cons | .0631488 .0232498 -7.50 0.000 .0306884 .129944
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.
. estimates store model_severity_split_1
. * line to read: Diabetes Yes, Odds ratio for Y > 0
. logit severity_above_moderate i.diabetes c.age i.female, or
Iteration 0: Log likelihood = -554.91824
Iteration 1: Log likelihood = -539.90815
Iteration 2: Log likelihood = -539.59871
Iteration 3: Log likelihood = -539.59856
Iteration 4: Log likelihood = -539.59856
Logistic regression Number of obs = 1,200
LR chi2(3) = 30.64
Prob > chi2 = 0.0000
Log likelihood = -539.59856 Pseudo R2 = 0.0276
------------------------------------------------------------------------------
severity_a~e | Odds ratio Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | 1.650193 .2683054 3.08 0.002 1.199879 2.269509
Discharge destination: relative risk ratios
Discharge destination has three categories with no order: home (0), rehabilitation unit (1) and nursing home (2). mlogit takes one category as the base and fits one equation for each other category against it, all in one model.
Write the base with its numeric code, baseoutcome(0). The rrr option prints exp(b), the relative risk ratio: the factor by which P(nursing home) / P(home) changes with diabetes. It is not the risk of a nursing home, and not a risk ratio for that destination.
Stata prints 2.699679 for nursing home (95% CI 1.868359 to 3.900892) and 1.191056 for rehabilitation (95% CI .8335177 to 1.701961). In clinical words: at the same age and sex, diabetes multiplies the nursing-home to home ratio by about 2.70. The rehabilitation ratio changes by 1.19, with an interval that includes 1.
* ---- 8. Unordered Y (discharge destination): multinomial logistic regression ----
* exp(b) = relative risk ratio: the factor by which P(Y=j)/P(Y=home) changes with diabetes.
* exp(b) = relative risk ratio: ตัวคูณของ P(Y=j)/P(Y=บ้าน) เมื่อเป็นเบาหวาน
mlogit dispo i.diabetes c.age i.female, baseoutcome(0) rrr
estimates store model_dispo_mlogit
* lines to read: Diabetes Yes in the Rehabilitation unit block and in the Nursing home block
. mlogit dispo i.diabetes c.age i.female, baseoutcome(0) rrr
Iteration 0: Log likelihood = -958.73585
Iteration 1: Log likelihood = -901.67976
Iteration 2: Log likelihood = -896.44756
Iteration 3: Log likelihood = -896.433
Iteration 4: Log likelihood = -896.433
Multinomial logistic regression Number of obs = 1,200
LR chi2(6) = 124.61
Prob > chi2 = 0.0000
Log likelihood = -896.433 Pseudo R2 = 0.0650
------------------------------------------------------------------------------
dispo | RRR Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
Home | (base outcome)
-------------+----------------------------------------------------------------
Rehabilita~t |
diabetes |
Yes | 1.191056 .2169103 0.96 0.337 .8335177 1.701961
age | 1.02692 .0073379 3.72 0.000 1.012638 1.041403
|
female |
Female | 1.140268 .184385 0.81 0.417 .8305481 1.565485
_cons | .033158 .0166743 -6.77 0.000 .0123749 .0888457
-------------+----------------------------------------------------------------
Nursing_home |
diabetes |
Yes | 2.699679 .5069876 5.29 0.000 1.868359 3.900892
age | 1.077819 .0095191 8.49 0.000 1.059322 1.096638
|
female |
Female | .8830964 .1654336 -0.66 0.507 .6117154 1.274873
_cons | .0006555 .0004381 -10.97 0.000 .0001769 .0024291
------------------------------------------------------------------------------
Note: _cons estimates baseline relative risk for each outcome.
Probabilities after mlogit: margins
Because a relative risk ratio compares two categories at once, it can mislead about either one. The same margins command gives each destination's predicted probability. Home falls from .7430646 to .6354724 and nursing home rises from .0967852 to .2057105. Rehabilitation hardly moves: .1601502 and .1588171.
So the rehabilitation ratio of 1.19 rose because home, the base, shrank, not because more patients went to rehabilitation. In clinical words: with diabetes, about 20.6% instead of 9.7% are predicted to go to a nursing home, and 63.5% instead of 74.3% to go home.
* Predicted probability of each destination, diabetes No vs Yes.
* ความน่าจะเป็นของแต่ละปลายทาง เบาหวาน No เทียบ Yes
margins diabetes, predict(outcome(0)) predict(outcome(1)) predict(outcome(2))
* lines to read: _predict 1 = Home, 2 = Rehabilitation unit, 3 = Nursing home
. margins diabetes, predict(outcome(0)) predict(outcome(1)) predict(outcome(2))
Predictive margins Number of obs = 1,200
Model VCE: OIM
1._predict: Pr(dispo==Home), predict(outcome(0))
2._predict: Pr(dispo==Rehabilitation_unit), predict(outcome(1))
3._predict: Pr(dispo==Nursing_home), predict(outcome(2))
------------------------------------------------------------------------------
| Delta-method
| Margin std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
_predict#|
diabetes |
1#No | .7430646 .0145694 51.00 0.000 .7145091 .7716201
1#Yes | .6354724 .0252601 25.16 0.000 .5859636 .6849812
2#No | .1601502 .0124594 12.85 0.000 .1357302 .1845703
2#Yes | .1588171 .0200992 7.90 0.000 .1194235 .1982107
3#No | .0967852 .0099076 9.77 0.000 .0773666 .1162037
3#Yes | .2057105 .0205245 10.02 0.000 .1654833 .2459377
------------------------------------------------------------------------------
Which category is the base?
Without baseoutcome(), Stata uses the most frequent category as the base, not the lowest code. Home is both here (code 0, and 854 of 1,200 patients), so the default prints e(baseout) = 0. Give home the code 2 and fit again: Stata still picks home and prints e(baseout) = 2. So always write baseoutcome(#).
* Without baseoutcome(): Stata picks the most frequent category as the base.
* ถ้าไม่เขียน baseoutcome() Stata ใช้กลุ่มที่พบบ่อยที่สุดเป็น base
mlogit dispo i.diabetes c.age i.female
display as text "base outcome chosen by Stata, e(baseout) = " e(baseout)
tabulate dispo
* Here Home is both the lowest code and the most frequent, so the two rules agree.
* Give Home the highest code (2) and fit again: the default base follows the frequency.
* ให้ Home เป็นรหัสสูงสุด (2) แล้ว fit ใหม่ base ที่ Stata เลือกตามความถี่ ไม่ใช่ตามรหัสต่ำสุด
recode dispo (0 = 2) (1 = 0) (2 = 1), generate(dispo_home_coded_2)
label define dispo_home_coded_2 0 "Rehabilitation unit" 1 "Nursing home" 2 "Home"
label values dispo_home_coded_2 dispo_home_coded_2
tabulate dispo_home_coded_2
quietly mlogit dispo_home_coded_2 i.diabetes c.age i.female
display as text "home coded 2: base outcome chosen by Stata, e(baseout) = " e(baseout)
. display as text "base outcome chosen by Stata, e(baseout) = " e(baseout)
base outcome chosen by Stata, e(baseout) = 0
. tabulate dispo
Discharge |
destination |
(unordered) | Freq. Percent Cum.
--------------------+-----------------------------------
Home | 854 71.17 71.17
Rehabilitation unit | 191 15.92 87.08
Nursing home | 155 12.92 100.00
--------------------+-----------------------------------
Total | 1,200 100.00
.
. * Here Home is both the lowest code and the most frequent, so the two rules a
> gree.
. * Give Home the highest code (2) and fit again: the default base follows the
> frequency.
. * ให้ Home เป็นรหัสสูงสุด (2) แล้ว fit ใหม่ base ที่ Stata เลือกตามความถี่ ไม
> ่ใช่ตามรหัสต่ำสุด
. recode dispo (0 = 2) (1 = 0) (2 = 1), generate(dispo_home_coded_2)
(1,200 differences between dispo and dispo_home_coded_2)
. label define dispo_home_coded_2 0 "Rehabilitation unit" 1 "Nursing home" 2 "H
> ome"
. label values dispo_home_coded_2 dispo_home_coded_2
. tabulate dispo_home_coded_2
RECODE of dispo |
(Discharge |
destination |
(unordered)) | Freq. Percent Cum.
--------------------+-----------------------------------
Rehabilitation unit | 191 15.92 15.92
Nursing home | 155 12.92 28.83
Home | 854 71.17 100.00
--------------------+-----------------------------------
Total | 1,200 100.00
. quietly mlogit dispo_home_coded_2 i.diabetes c.age i.female
. display as text "home coded 2: base outcome chosen by Stata, e(baseout) = " e
> (baseout)
home coded 2: base outcome chosen by Stata, e(baseout) = 2
Readmissions: counts and rates
Readmissions are counts per patient. poisson models the log of the expected count, and the irr option prints exp(b), the incidence rate ratio. Stata prints 1.524033 (95% CI 1.302227 to 1.783619). In clinical words: at the same age and sex, patients with diabetes have about 1.52 times as many readmissions, but this ignores that patients were followed for different lengths of time; the per person-year rate below is the fair comparison.
A Poisson model assumes the variance equals the mean. When counts spread out more, nbreg adds a dispersion parameter, alpha, that measures the extra spread. Here nbreg gives an incidence rate ratio of 1.513345.
Its alpha (count model, no exposure(fu_years)) is 1.08104; alpha = 0 would mean no extra spread, and Stata's test of alpha = 0 rejects that (chibar2(01) = 126.13, P below 0.001). So these counts do spread out more than Poisson allows, yet the effect barely moves. What to do about the extra spread is in Checking a Regression Model: Assumptions, Diagnostics and What to Do When They Fail.
* ---- 9. Count Y (readmissions): Poisson, then negative binomial ----
* exp(b) = incidence rate ratio of readmissions per patient.
* exp(b) = incidence rate ratio ของจำนวนครั้งการกลับมานอนซ้ำต่อผู้ป่วย
poisson readmit_n i.diabetes c.age i.female, irr
estimates store model_readmit_poisson
* line to read: Diabetes Yes, IRR [95% CI]
. poisson readmit_n i.diabetes c.age i.female, irr
Iteration 0: Log likelihood = -1276.6788
Iteration 1: Log likelihood = -1276.6788
Poisson regression Number of obs = 1,200
LR chi2(3) = 40.36
Prob > chi2 = 0.0000
Log likelihood = -1276.6788 Pseudo R2 = 0.0156
------------------------------------------------------------------------------
readmit_n | IRR Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | 1.524033 .1223012 5.25 0.000 1.302227 1.783619
age | 1.009459 .0033395 2.85 0.004 1.002934 1.016025
|
female |
Female | 1.106422 .0853719 1.31 0.190 .9511338 1.287063
_cons | .2462585 .0575233 -6.00 0.000 .1557973 .3892445
------------------------------------------------------------------------------
Note: _cons estimates baseline incidence rate.
nbreg readmit_n i.diabetes c.age i.female, irr
estimates store model_readmit_nbreg
* lines to read: Diabetes Yes, IRR [95% CI]; /lnalpha and alpha; LR test of alpha=0
Negative binomial regression Number of obs = 1,200
LR chi2(3) = 23.64
Dispersion: mean Prob > chi2 = 0.0000
Log likelihood = -1213.6133 Pseudo R2 = 0.0096
------------------------------------------------------------------------------
readmit_n | IRR Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | 1.513345 .1599163 3.92 0.000 1.230243 1.861594
age | 1.009042 .0042533 2.14 0.033 1.00074 1.017413
|
female |
Female | 1.107698 .1093 1.04 0.300 .9129155 1.344039
_cons | .2537936 .074885 -4.65 0.000 .1423387 .4525206
-------------+----------------------------------------------------------------
/lnalpha | .0779231 .1413004 -.1990205 .3548668
-------------+----------------------------------------------------------------
alpha | 1.08104 .1527513 .8195331 1.425991
------------------------------------------------------------------------------
Note: Estimates are transformed only in the first equation to incidence-rate
ratios.
Note: _cons estimates baseline incidence rate.
LR test of alpha=0: chibar2(01) = 126.13 Prob >= chibar2 = 0.000
Per person-year: the exposure() option
Follow-up time differed, so the fair comparison is readmissions per person-year. exposure(fu_years) adds the log of each patient's follow-up with its coefficient fixed at 1. That fixed term is called an offset, and it turns a count into a rate; the output marks it (exposure).
Stata prints 1.577806 (95% CI 1.347871 to 1.846965). In clinical words: patients with diabetes are readmitted at about 1.58 times the rate per person-year. This interval assumes the variance equals the mean, and the counts above spread out more than that.
The nbreg version, the second pane below, gives 1.514983 (95% CI 1.241992 to 1.847977), a wider interval. Which interval to report is shown in the third post, Checking a Regression Model: Assumptions, Diagnostics and What to Do When They Fail. Rates and offsets are taught in Rates, Poisson Regression, and the Missing Lambda Backbone.
* ---- 10. Rate Y (readmissions per person-year): Poisson with exposure() ----
* exposure(fu_years) puts log follow-up in as an offset, so exp(b) = ratio of rates per person-year.
* exposure(fu_years) ใส่ log ของระยะติดตามเป็น offset exp(b) จึงเป็นอัตราส่วนของ rate ต่อ person-year
poisson readmit_n i.diabetes c.age i.female, exposure(fu_years) irr
estimates store model_readmit_rate_poisson
* line to read: Diabetes Yes, IRR [95% CI]; ln(fu_years) shown with (exposure)
. poisson readmit_n i.diabetes c.age i.female, exposure(fu_years) irr
Iteration 0: Log likelihood = -1206.2177
Iteration 1: Log likelihood = -1206.2177
Poisson regression Number of obs = 1,200
LR chi2(3) = 43.24
Prob > chi2 = 0.0000
Log likelihood = -1206.2177 Pseudo R2 = 0.0176
------------------------------------------------------------------------------
readmit_n | IRR Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | 1.577806 .1267972 5.67 0.000 1.347871 1.846965
age | 1.008897 .00335 2.67 0.008 1.002353 1.015485
|
female |
Female | 1.068134 .082401 0.85 0.393 .9182479 1.242486
_cons | .2297324 .0538322 -6.28 0.000 .1451323 .3636474
ln(fu_years) | 1 (exposure)
------------------------------------------------------------------------------
Note: _cons estimates baseline incidence rate.
* The same rate with a negative binomial model (the counts are overdispersed, see 03).
* rate เดียวกันด้วย negative binomial (count กระจายเกิน ดู 03)
nbreg readmit_n i.diabetes c.age i.female, exposure(fu_years) irr
estimates store model_readmit_rate_nbreg
* line to read: Diabetes Yes, IRR [95% CI]
Negative binomial regression Number of obs = 1,200
LR chi2(3) = 26.29
Dispersion: mean Prob > chi2 = 0.0000
Log likelihood = -1167.5091 Pseudo R2 = 0.0111
------------------------------------------------------------------------------
readmit_n | IRR Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | 1.514983 .1535783 4.10 0.000 1.241992 1.847977
age | 1.010164 .0041202 2.48 0.013 1.002121 1.018272
|
female |
Female | 1.062921 .1008768 0.64 0.520 .882506 1.28022
_cons | .2142607 .0612126 -5.39 0.000 .1223942 .37508
ln(fu_years) | 1 (exposure)
-------------+----------------------------------------------------------------
/lnalpha | -.2828409 .1688926 -.6138643 .0481825
-------------+----------------------------------------------------------------
alpha | .7536397 .1272842 .5412552 1.049362
------------------------------------------------------------------------------
Note: Estimates are transformed only in the first equation to incidence-rate
ratios.
Note: _cons estimates baseline incidence rate.
LR test of alpha=0: chibar2(01) = 77.42 Prob >= chibar2 = 0.000
Time to death: stset first, then stcox
Time to death needs two facts: how long each patient was followed, and whether follow-up ended in death. stset time_d, failure(died) declares both once, and stcox then takes only the covariates. Writing the outcome into stcox is a mistake.
The stset output confirms 222 deaths in 391,391 days at risk. Cox regression prints a hazard ratio of 1.918519 (95% CI 1.46799 to 2.507317). In clinical words: at any point in the year after admission, a patient with diabetes dies at about 1.92 times the rate of a patient without diabetes of the same age and sex.
Cox regression is taught in Cox Proportional Hazards Regression and Related Survival-Analysis Concepts. Checking that the ratio holds over time is in Checking a Regression Model: Assumptions, Diagnostics and What to Do When They Fail.
* ---- 11. Time-to-event Y (death within 365 days): Cox regression ----
* stset declares time and event once; stcox then takes only the covariates.
* stset บอกเวลาและเหตุการณ์ครั้งเดียว แล้ว stcox ใส่เฉพาะตัวแปรอิสระ
stset time_d, failure(died)
stcox i.diabetes c.age i.female
estimates store model_death_cox
* line to read: Diabetes Yes, Haz. ratio [95% CI]
. stset time_d, failure(died)
Survival-time data settings
Failure event: died!=0 & died<.
Observed time interval: (0, time_d]
Exit on or before: failure
--------------------------------------------------------------------------
1,200 total observations
0 exclusions
--------------------------------------------------------------------------
1,200 observations remaining, representing
222 failures in single-record/single-failure data
391,391 total analysis time at risk and under observation
At risk from t = 0
Earliest observed entry t = 0
Last observed exit t = 365
. stcox i.diabetes c.age i.female
Failure _d: died
Analysis time _t: time_d
Iteration 0: Log likelihood = -1552.2399
Iteration 1: Log likelihood = -1509.9605
Iteration 2: Log likelihood = -1509.6317
Iteration 3: Log likelihood = -1509.6317
Refining estimates:
Iteration 0: Log likelihood = -1509.6317
Cox regression with Breslow method for ties
No. of subjects = 1,200 Number of obs = 1,200
No. of failures = 222
Time at risk = 391,391
LR chi2(3) = 85.22
Log likelihood = -1509.6317 Prob > chi2 = 0.0000
------------------------------------------------------------------------------
_t | Haz. ratio Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | 1.918519 .2619999 4.77 0.000 1.46799 2.507317
age | 1.039789 .0062316 6.51 0.000 1.027647 1.052075
|
female |
Female | .5688773 .0813645 -3.94 0.000 .4298078 .7529445
------------------------------------------------------------------------------
Patients from the same hospital: what vce(cluster hospital) changes
The 1,200 patients come from 12 hospitals, and patients in one hospital share its doctors and ICU policy. vce(cluster hospital) keeps the model but computes the standard error from hospitals instead of single patients.
Fit the ICU logit twice. The odds ratio stays 1.646897. The standard error grows from .2387784 to .2858684, the interval widens from 1.239519 to 2.188162 into 1.171965 to 2.314291, and the p-value moves from 0.001 to 0.004.
The small table at the end of the pane puts the same fit on the log-odds scale: b = 0.4989 in both fits, with the standard error going from 0.1450 to 0.1736. The standard error of the odds ratio is that figure times the odds ratio.
In clinical words: the estimate is unchanged, but we are less sure of it. With only 12 hospitals the clustered standard error is itself rough; when to cluster is taught in Understanding the VCE: Robust Standard Errors, the Sandwich Estimator and vce(cluster id).
* ---- 12. Clustered patients (hospital): plain SE next to cluster-robust SE ----
* Same logistic model twice; only the standard error changes, the OR stays the same.
* logistic model เดียวกันสองครั้ง เปลี่ยนแค่ standard error ค่า OR เท่าเดิม
logit icu i.diabetes c.age i.female, or
estimates store model_icu_logit_plain
logit icu i.diabetes c.age i.female, or vce(cluster hospital)
estimates store model_icu_logit_cluster
* side by side on the log-odds scale: b and SE for diabetes, plain vs cluster
* วางคู่กันบน log-odds scale: b และ SE ของเบาหวาน แบบธรรมดาเทียบ cluster
estimates table model_icu_logit_plain model_icu_logit_cluster, keep(1.diabetes) b(%9.4f) se(%9.4f)
. logit icu i.diabetes c.age i.female, or vce(cluster hospital)
Iteration 0: Log pseudolikelihood = -684.51086
Iteration 1: Log pseudolikelihood = -655.55088
Iteration 2: Log pseudolikelihood = -655.09143
Iteration 3: Log pseudolikelihood = -655.09116
Iteration 4: Log pseudolikelihood = -655.09116
Logistic regression Number of obs = 1,200
Wald chi2(3) = 43.97
Prob > chi2 = 0.0000
Log pseudolikelihood = -655.09116 Pseudo R2 = 0.0430
(Std. err. adjusted for 12 clusters in hospital)
------------------------------------------------------------------------------
| Robust
icu | Odds ratio std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
diabetes |
Yes | 1.646897 .2858684 2.87 0.004 1.171965 2.314291
age | 1.03403 .0069643 4.97 0.000 1.02047 1.047771
|
female |
Female | .636516 .0679878 -4.23 0.000 .5162861 .7847442
_cons | .0356252 .0184391 -6.44 0.000 .0129177 .0982489
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.
. estimates store model_icu_logit_cluster
. * side by side on the log-odds scale: b and SE for diabetes, plain vs cluster
. * วางคู่กันบน log-odds scale: b และ SE ของเบาหวาน แบบธรรมดาเทียบ cluster
. estimates table model_icu_logit_plain model_icu_logit_cluster, keep(1.diabete
> s) b(%9.4f) se(%9.4f)
--------------------------------------
Variable | model_i~n model_i~r
-------------+------------------------
diabetes |
Yes | 0.4989 0.4989
| 0.1450 0.1736
--------------------------------------
Legend: b/se
Summary: from the outcome to one sentence
| Outcome | Command | Number Stata prints | What it is called | How to say it |
|---|---|---|---|---|
| Length of stay (days) | regress los i.diabetes c.age i.female | 1.436325 | difference in means (Coefficient) | About 1.44 more days in hospital with diabetes. |
| ICU admission, crude | cs icu diabetes, or | .116849; 1.517813; 1.787558 | risk difference; risk ratio; odds ratio | Three answers from one table, before adjustment. |
| ICU admission | logit icu i.diabetes c.age i.female, or | 1.646897 | odds ratio | About 1.65 times the odds of ICU admission. |
| ICU admission | glm icu i.diabetes c.age i.female, family(poisson) link(log) vce(robust) eform | 1.413388 | risk ratio (column says IRR) | About 1.41 times the risk of ICU admission. |
| ICU admission | glm icu i.diabetes c.age i.female, family(binomial) link(identity) | .0937788 | risk difference | About 9.4 more ICU admissions in every 100 patients. |
| Severity grade | ologit severity i.diabetes c.age i.female, or | 1.898396 | cumulative odds ratio | About 1.90 times the odds of a worse grade, at either cut. |
| Discharge destination | mlogit dispo i.diabetes c.age i.female, baseoutcome(0) rrr | 2.699679 (nursing home) | relative risk ratio against home | The nursing-home to home ratio is about 2.70 times larger. |
| Readmissions (count) | poisson readmit_n i.diabetes c.age i.female, irr | 1.524033 | incidence rate ratio | About 1.52 times as many readmissions, ignoring follow-up time; the rate row below is the fair comparison. |
| Readmissions per person-year | poisson readmit_n i.diabetes c.age i.female, exposure(fu_years) irr | 1.577806 | incidence rate ratio (a rate) | About 1.58 times the readmission rate; the interval assumes the variance equals the mean, which fails here (see nbreg above). |
| Death within 365 days | stset time_d, failure(died), then stcox i.diabetes c.age i.female | 1.918519 | hazard ratio | Dies at about 1.92 times the rate at any point in the year. |
| ICU admission, 12 hospitals | logit icu i.diabetes c.age i.female, or vce(cluster hospital) | 1.646897 (SE .2858684) | the same odds ratio, cluster-robust standard error | Same estimate, wider interval. |
Syntax that fails, or reads wrong
-
A second comma before an option
glm icu i.diabetes, family(binomial), eform has two commas, and Stata refuses the line.
Fix: Write one comma, then every option separated by spaces: glm icu i.diabetes c.age i.female, family(binomial) link(log) eform.
-
The outcome written into stcox
stcox takes no outcome. The time and the event come from stset, so a variable written first is read as one more covariate.
Fix: Run stset time_d, failure(died) once, then stcox i.diabetes c.age i.female.
-
family(nbinomial) read as a model of the extra spread
glm with family(nbinomial) fixes the dispersion at 1 unless you write family(nbinomial ml), so it does not estimate the extra spread.
Fix: Use nbreg, which estimates alpha and tests alpha = 0.
-
No base, or a word as the base
mlogit without baseoutcome() uses the most frequent category, and base(reference) is not Stata syntax.
Fix: Write baseoutcome(#) with the numeric code of the category you want.
References
- Zou G. A modified Poisson regression approach to prospective studies with binary data. American Journal of Epidemiology 2004;159(7):702-706. https://doi.org/10.1093/aje/kwh090
- McCullagh P. Regression models for ordinal data. Journal of the Royal Statistical Society, Series B 1980;42(2):109-142. https://doi.org/10.1111/j.2517-6161.1980.tb01109.x
- Cox DR. Regression models and life-tables. Journal of the Royal Statistical Society, Series B 1972;34(2):187-220. https://doi.org/10.1111/j.2517-6161.1972.tb00899.x
- Long JS, Freese J. Regression Models for Categorical Dependent Variables Using Stata. 3rd edition. College Station, TX: Stata Press; 2014.
Key takeaways
- For every model, read the row Yes under diabetes, then the column header: Stata names the number for you.
- One ICU table gives three answers: a risk difference of .116849, a risk ratio of 1.517813 and an odds ratio of 1.787558.
- A log-binomial fit can fail quietly: look for convergence not achieved, dots for standard errors and e(converged) = 0, then use modified Poisson.
- After ologit and mlogit, run margins: a cumulative odds ratio of 1.90 and a relative risk ratio of 1.19 make sense only as predicted probabilities.
- Write baseoutcome(#), use exposure() for rates and stset before stcox; vce(cluster) changes the standard error, not the estimate.
Related in the wiki: Which Regression Model? A Decision Flow from Study Design and Outcome (Y) to the Stata Command · Checking a Regression Model: Assumptions, Diagnostics and What to Do When They Fail · Link and Family: One Picks Your Effect Measure, the Other Your Standard Error · Getting a Risk Ratio for a Common Outcome: The Step-Down When Log-Binomial Hits the Wall · Multinomial vs Ordinal Logistic Regression [mlogit & ologit]: Choosing the Right Model for Categorical Outcomes · Rates, Poisson Regression, and the Missing Lambda Backbone · Cox Proportional Hazards Regression and Related Survival-Analysis Concepts · Understanding the VCE: Robust Standard Errors, the Sandwich Estimator and vce(cluster id)