Thanks to Kit Baum, a new package -mrgreg2- is now available on SSC.
Description
The output from the mrgtbl2 command is based on margins from the regression model: outcome = constant + i.exposure[#i.by1][#i.by2] + adjustment variables.
The user specifies the regression method as one of regress, cnsreg, mixed, glm, poisson, nbreg, logit, probit, cloglog, binreg, meprobit, melogit, mepoisson, menbreg, meglm, or mecloglog
Margins calculates metrics, such as linear predictions, probabilities, or risk differences, based on a fitted model's response over a dataset where some or all covariates are fixed at specific values. Margins answers the question: "What does my model have to say about such-and-such scenario?" The scenario in mrgtbl2 is the standard table 2, including confounding by the option adjustments and stratification by the options by1 and by2.
There is a conceptual and numerical relationship between the margins command and the Mantel–Haenszel method, as both tools are used to adjust for confounding factors and provide comparable estimates across stratified groups.
In the absence of adjustments and stratifications, the output table is applicable for reporting in RCTs.
Examples
Analyzing the effect of whether mothers are smoking on the birthweight stratified by race and hypertension using the mixed regression command (the default), adjusted for age, and with robust variance estimation in wide format. A row equation label is added.
The same as above, with the report in long format (the default) and the Option noquietly to display the regression and margin logging behind the Table 2 report.
The command returns a list of allowed regressions, the applied regression command, the applied margins commands, and the Table 2 matrix.
The estimates of the margins command are stored in _mrgtbl2 for further analysis. A marginsplot of Table 2 is, for example, easily produced.

There are plenty more examples in the help file.
Enjoy
Description
The output from the mrgtbl2 command is based on margins from the regression model: outcome = constant + i.exposure[#i.by1][#i.by2] + adjustment variables.
The user specifies the regression method as one of regress, cnsreg, mixed, glm, poisson, nbreg, logit, probit, cloglog, binreg, meprobit, melogit, mepoisson, menbreg, meglm, or mecloglog
Margins calculates metrics, such as linear predictions, probabilities, or risk differences, based on a fitted model's response over a dataset where some or all covariates are fixed at specific values. Margins answers the question: "What does my model have to say about such-and-such scenario?" The scenario in mrgtbl2 is the standard table 2, including confounding by the option adjustments and stratification by the options by1 and by2.
There is a conceptual and numerical relationship between the margins command and the Mantel–Haenszel method, as both tools are used to adjust for confounding factors and provide comparable estimates across stratified groups.
In the absence of adjustments and stratifications, the output table is applicable for reporting in RCTs.
Examples
Analyzing the effect of whether mothers are smoking on the birthweight stratified by race and hypertension using the mixed regression command (the default), adjusted for age, and with robust variance estimation in wide format. A row equation label is added.
Code:
. webuse lbw, clear
. mrgtbl2, o(bwt) e(smoke) by(race) by2(ht) a(age) vce(robust) roweq(First) w
| Smoker | Nonsmoker | mrg(1vs0)
| mrg(1) [95% CI] | mrg(0) [95% CI] | mrg(vsRef) [95% CI] P(mrg(v~)
---------------------------------+---------------------------------+---------------------------------+-------------------------------------------
First | | |
ht(0)&White | 2820.439 2635.714 3005.164 | 3427.157 3224.476 3629.838 | -606.7186 -881.6169 -331.8204 .0000152
ht(0)&Black | 2656.875 2230.317 3083.434 | 2824.438 2476.195 3172.682 | -167.563 -717.6811 382.5552 .5505113
ht(0)&Other | 2759.536 2389.879 3129.192 | 2876.458 2696.224 3056.692 | -116.9224 -527.5114 293.6667 .576753
ht(1)&White | 2927.893 2285.131 3570.656 | 3103.974 1824.154 4383.793 | -176.0806 -1607.226 1255.065 .8094438
ht(1)&Black | 1100.457 -195.4356 2396.35 | 3149.684 2243.866 4055.501 | -2049.226 -3635.825 -462.6276 .0113589
ht(1)&Other | . . . | 2059.502 1419.411 2699.593 | . . . .
Code:
. mrgtbl2, o(bwt) e(smoke) by(race) by2(ht) a(age) vce(robust) noq
. mixed bwt i.smoke#i.race#i.ht age ,
note: 1.smoke#3.race#1.ht identifies no observations in the sample.
Mixed-effects ML regression Number of obs = 189
Wald chi2(11) = 45.41
Log likelihood = -1493.16 Prob > chi2 = 0.0000
------------------------------------------------------------------------------------
bwt | Coefficient Std. err. z P>|z| [95% conf. interval]
-------------------+----------------------------------------------------------------
smoke#race#ht |
Nonsmoker#White#1 | -323.183 661.627 -0.49 0.63 -1619.948 973.582
Nonsmoker#Black#0 | -602.719 210.089 -2.87 0.00 -1014.486 -190.952
Nonsmoker#Black#1 | -277.474 474.869 -0.58 0.56 -1208.200 653.253
Nonsmoker#Other#0 | -550.699 140.374 -3.92 0.00 -825.828 -275.570
Nonsmoker#Other#1 | -1367.655 341.762 -4.00 0.00 -2037.495 -697.815
Smoker#White#0 | -606.719 140.257 -4.33 0.00 -881.617 -331.820
Smoker#White#1 | -499.264 346.410 -1.44 0.15 -1178.216 179.688
Smoker#Black#0 | -770.282 241.223 -3.19 0.00 -1243.069 -297.494
Smoker#Black#1 | -2326.700 664.841 -3.50 0.00 -3629.764 -1023.635
Smoker#Other#0 | -667.621 216.023 -3.09 0.00 -1091.018 -244.225
Smoker#Other#1 | 0.000 (empty)
|
age | 3.210 9.711 0.33 0.74 -15.823 22.243
_cons | 3352.570 272.455 12.31 0.00 2818.567 3886.572
------------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
var(Residual) | 4.26e+05 43846.822 3.48e+05 5.21e+05
------------------------------------------------------------------------------
. margins smoke#race#ht, post
Predictive margins Number of obs = 189
Expression: Linear prediction, fixed portion, predict()
------------------------------------------------------------------------------------
| Delta-method
| Margin std. err. z P>|z| [95% conf. interval]
-------------------+----------------------------------------------------------------
smoke#race#ht |
Nonsmoker#White#0 | 3427.157 103.411 33.14 0.00 3224.476 3629.838
Nonsmoker#White#1 | 3103.974 652.981 4.75 0.00 1824.154 4383.793
Nonsmoker#Black#0 | 2824.438 177.679 15.90 0.00 2476.195 3172.682
Nonsmoker#Black#1 | 3149.684 462.160 6.82 0.00 2243.866 4055.501
Nonsmoker#Other#0 | 2876.458 91.958 31.28 0.00 2696.224 3056.692
Nonsmoker#Other#1 | 2059.502 326.583 6.31 0.00 1419.411 2699.593
Smoker#White#0 | 2820.439 94.249 29.93 0.00 2635.714 3005.164
Smoker#White#1 | 2927.893 327.946 8.93 0.00 2285.131 3570.656
Smoker#Black#0 | 2656.875 217.636 12.21 0.00 2230.317 3083.434
Smoker#Black#1 | 1100.457 661.182 1.66 0.10 -195.436 2396.350
Smoker#Other#0 | 2759.536 188.604 14.63 0.00 2389.879 3129.192
Smoker#Other#1 | . (not estimable)
------------------------------------------------------------------------------------
| mrg [95% CI] mrg(vsRef) [95% CI] P(mrg(v~)
---------------------------------+----------------------------------------------------------------------------
ht(0)&White |
Nonsmoker | 3427.157 3224.476 3629.838 . . . .
Smoker | 2820.439 2635.714 3005.164 -606.7186 -881.6169 -331.8204 .0000152
---------------------------------+----------------------------------------------------------------------------
ht(0)&Black |
Nonsmoker | 2824.438 2476.195 3172.682 . . . .
Smoker | 2656.875 2230.317 3083.434 -167.563 -717.6811 382.5552 .5505113
---------------------------------+----------------------------------------------------------------------------
ht(0)&Other |
Nonsmoker | 2876.458 2696.224 3056.692 . . . .
Smoker | 2759.536 2389.879 3129.192 -116.9224 -527.5114 293.6667 .576753
---------------------------------+----------------------------------------------------------------------------
ht(1)&White |
Nonsmoker | 3103.974 1824.154 4383.793 . . . .
Smoker | 2927.893 2285.131 3570.656 -176.0806 -1607.226 1255.065 .8094438
---------------------------------+----------------------------------------------------------------------------
ht(1)&Black |
Nonsmoker | 3149.684 2243.866 4055.501 . . . .
Smoker | 1100.457 -195.4356 2396.35 -2049.226 -3635.825 -462.6276 .0113589
---------------------------------+----------------------------------------------------------------------------
ht(1)&Other |
Nonsmoker | 2059.502 1419.411 2699.593 . . . .
Smoker | . . . . . . .
Code:
. return list
macros:
r(poscmds) : "regress", "cnsreg", "mixed", "glm", "poisson", "nbreg", "logit", "probit", "cloglog", "binreg", "meprobit", "melogit", "mepoisson", "menbreg", "meglm", "mecloglog"
r(mrgcmd) : "margins smoke#race#ht, post"
r(regcmd) : "mixed bwt i.smoke#i.race#i.ht age ,"
matrices:
r(mrgtbl2) : 12 x 7
Code:
. marginsplot, x(race ht) horiz Variables that uniquely identify margins: smoke race ht
There are plenty more examples in the help file.
Enjoy

Comment