What is -regmat-

regmat is prefix command to a regression template. A regression template is simply a regression command. Each combination of one outcome variable, one exposure variable and one adjustment set is inserted just after the regression command. Then all regression estimates of exposures are placed in a matrix ordered by outcome and exposure variables rowwise and adjustment columnwise.

The resulting matrix is saved in the return list for further usage.

The matprint options makes it easy to integrate the result table into a log2markup output file.

Together with the basetable the command regmat generates the two typical tables for reporting epidemiological research. The resulting tables are easy to integrate into the final text using eg. log2markup output file or -putexcel-.

-regmat- is a part of the package matrixtools.

Syntax

The syntax is: regmat [using], outcomes(varlist) exposures(varlist) [adjustements(varlist strings) noquietly labels base keep(string) drop(string) Matprint options] , regression template

Options

To see -matprint- options

Stored results

-regmat- stores the following in r():

local

Matrix

Versions

-regmat- is tested in version 12.1 ic, 13.1 ic, 14.2 ic, and 15.1 ic.

Installation

To install use the command: ssc install matrixtools

A demonstration of -regmat-

Background

The data is from Hosmer and Lemeshow, Applied logistic regression, 1989 and the description from Rachel MacKay Altman's old homepage

Low birth weight is an outcome that has been of concern to physicians for years.

This is due to the fact that infant mortality rates and birth defect rates are very high for low birth weight babies.

A woman's behaviour during pregnancy (including diet, smoking habits, and receiving prenatal care) can greatly alter the chances of carrying the baby to term and, consequently, of delivering a baby of normal birth weight.

Objective

The objective here is to see if smoking during pregnancy has an effect on birth weights.

The dataset

webuse lbw, clear

rename low bwlt2500
generate bwlt1500 = bwt < 1500 if !missing(bwt)
label variable bwlt1500 "birthweight < 1500g"
label define no_yes 0 "No" 1 "Yes"
label values ht ui smoke bwlt* no_yes
replace ftv = 3 if ftv > 3
label define ftv 3 "3-"
label values ftv ftv

Outcomes, exposures, and confounders

Primary outcome is birthweight in grams (bwt). Two secondary outcomes are whether a newborn weighs less than 2500 grams (bwlt2500) and weighs less than 1500 grams (bwlt1500).

Exposure is whether the mothers has been smoking or not during pregnancy (smoke) and whether the mothers have had hypertension or not (ht).

Confounders to be included are number of visits to physician during 1st trimester (ftv), mothers age (age), mothers race (race), and presence of uterine irritability (ui).

The Analysis

Using the -basetable- command

basetable smoke age(%6.1f) ftv(%6.1f, iqi) ftv(c) ui(Yes), style(html) ///
        caption(Comparing confounders by exposure (*smoke*) )

gives the following summary table for exposure smoke

Comparing confounders by exposure (*smoke*)
Columns by: smoked during pregnancy No Yes TotalP-value
n (%) 115 (60.8) 74 (39.2) 189 (100.0)
age of mother, mean (sd) 23.4 (5.5) 22.9 (5.0) 23.2 (5.3) 0.54
number of visits to physician during 1st trimester, median (iqi)1.0 (0.0; 1.0)0.0 (0.0; 1.0)0.0 (0.0; 1.0) 0.30
number of visits to physician during 1st trimester, n (%)
0, n (%) 55 (47.8) 45 (60.8) 100 (52.9)
1, n (%) 35 (30.4) 12 (16.2) 47 (24.9)
2, n (%) 19 (16.5) 11 (14.9) 30 (15.9)
3-, n (%) 6 (5.2) 6 (8.1) 12 (6.3) 0.12
presence, uterine irritability (Yes), n (%) 15 (13.0) 13 (17.6) 28 (14.8) 0.39

And likewise for exposure race.

Comparing confounders by exposure (*race*)
Columns by: race white black other TotalP-value
n (%) 96 (50.8) 26 (13.8) 67 (35.4) 189 (100.0)
age of mother, mean (sd) 24.3 (5.7) 21.5 (5.1) 22.4 (4.5) 23.2 (5.3) 0.02
number of visits to physician during 1st trimester, median (iqi)1.0 (0.0; 1.8)0.0 (0.0; 1.3)0.0 (0.0; 1.0)0.0 (0.0; 1.0) 0.15
number of visits to physician during 1st trimester, n (%)
0, n (%) 43 (44.8) 14 (53.8) 43 (64.2) 100 (52.9)
1, n (%) 29 (30.2) 6 (23.1) 12 (17.9) 47 (24.9)
2, n (%) 18 (18.8) 4 (15.4) 8 (11.9) 30 (15.9)
3-, n (%) 6 (6.3) 2 (7.7) 4 (6.0) 12 (6.3) 0.37
presence, uterine irritability (Yes), n (%) 13 (13.5) 3 (11.5) 12 (17.9) 28 (14.8) 0.65

Crude and adjusted estimates of the effect of smoke and ht on the primary outcome bwt can be summarised by the command

regmat, outcomes(bwt) exposure(i.smoke i.race) adjustments("" "age i.ftv i.ui") /// 
        title(Crude and adjusted estimates of the effect of *smoke' and *race* on *bwt*) ///
        style(html): regress
Crude (Adjustment 1) and adjusted (Adjustment 2: *age*, *ftv* and *ui*) estimates of the effect of *smoke' and *race* on *bwt*
Adjustment 1 Adjustment 2
b se(b)Lower 95% CIUpper 95% CIP value b se(b)Lower 95% CIUpper 95% CIP value
bwtsmoke(1) -282.66106.95 -493.65 -71.67 0.01 -228.92105.10 -436.28 -21.55 0.03
race(2) -383.32157.89 -694.81 -71.83 0.02 -374.90154.86 -680.47 -69.33 0.02
race(3) -299.00113.69 -523.28 -74.71 0.01 -246.46112.56 -468.55 -24.37 0.03

Option labels let one see labels if possible. Option base adds base values in output. Option drop(se p) removes the se and p columns from output.

regmat, outcome(bwt) exposure(i.smoke i.race) adjustments("" "age i.ftv i.ui") ///
        title(Crude (Adjustment 1) and adjusted (Adjustment 2: *age*, *ftv* and *ui*) ///
        estimates of the effect of *smoke' and *race* on *bwt*) ///
        labels base style(html) drop(se p): regress
Crude (Adjustment 1) and adjusted (Adjustment 2: *age*, *ftv* and *ui*) estimates of the effect of *smoke' and *race* on *bwt*
Adjustment 1 Adjustment 2
bLower 95% CIUpper 95% CI bLower 95% CIUpper 95% CI
birthweight(grams)smoked during pregnancy (No) 0.00 0.00 0.00 0.00 0.00 0.00
smoked during pregnancy (Yes) -282.66 -493.65 -71.67 -228.92 -436.28 -21.55
race(white) 0.00 0.00 0.00 0.00 0.00 0.00
race(black) -383.32 -694.81 -71.83 -374.90 -680.47 -69.33
race(other) -299.00 -523.28 -74.71 -246.46 -468.55 -24.37

The return list contains the adjustments and the estimates in a matrix.

return list

macros:
       r(Adjustment_2) : "age i.ftv i.ui"
       r(Adjustment_1) : "Crude"

matrices:
             r(regmat) :  5 x 6

The estimates in the matrix looks like:

matprint r(regmat), decimals(3)

-------------------------------------------------------------------------------------------------------------------------------------
                                                   Adjustment 1                              Adjustment 2                            
                                                              b  Lower 95% CI  Upper 95% CI             b  Lower 95% CI  Upper 95% CI
-------------------------------------------------------------------------------------------------------------------------------------
birthweight(grams)  smoked during pregnancy (No)          0.000         0.000         0.000         0.000         0.000         0.000
                    smoked during pregnancy (Yes)      -282.659      -493.652       -71.667      -228.915      -436.279       -21.552
                    race(white)                           0.000         0.000         0.000         0.000         0.000         0.000
                    race(black)                        -383.318      -694.806       -71.830      -374.901      -680.471       -69.332
                    race(other)                        -298.995      -523.283       -74.708      -246.460      -468.551       -24.369
-------------------------------------------------------------------------------------------------------------------------------------

This matrix is saved for later use.

matrix tbl2 = r(regmat)

Crude estimates as well as estimates adjusted for age, ftv, and ui of the effects of smoke and ht on the two secondary outcomes bwlt2500 and bwlt1500 is presented below.

Note that the same type of regression (template: logit, vce(robust) or) is used.

regmat, outcome(bwlt2500 bwlt1500) exposure(i.smoke i.race) ///
        adjustments("" "age i.ftv i.ui") labels base style(html) ///
        title(Crude (Adjustment 1) and adjusted (Adjustment 2: *age*, *ftv* and *ui*) ///
        estimates of the effect of *smoke' and *race* on *bwt*) ///
        drop(se p): logit, vce(robust) or
Crude (Adjustment 1) and adjusted (Adjustment 2: *age*, *ftv* and *ui*) estimates of the effect of *smoke' and *race* on *bwt*
Adjustment 1 Adjustment 2
bLower 95% CIUpper 95% CI bLower 95% CIUpper 95% CI
birthweight<2500g smoked during pregnancy (No) 0.00 0.00 0.00 0.00 0.00 0.00
smoked during pregnancy (Yes) 0.70 0.08 1.33 0.60 -0.06 1.26
race(white) 0.00 0.00 0.00 0.00 0.00 0.00
race(black) 0.84 -0.07 1.76 0.78 -0.18 1.74
race(other) 0.64 -0.05 1.32 0.50 -0.21 1.21
birthweight < 1500gsmoked during pregnancy (No) 0.00 0.00 0.00 0.00 0.00 0.00
smoked during pregnancy (Yes) 0.04 -1.78 1.85 -0.05 -2.31 2.22
race(white) 0.00 0.00 0.00 0.00 0.00 0.00
race(black) 1.34 -1.48 4.15 1.11 -2.26 4.47
race(other) 1.49 -0.80 3.78 1.61 -1.31 4.54

Estimates from primary and secondary outcomes can be aggregated by matrix operations.

matrix tbl2 = tbl2 \ r(regmat)
matprint tbl2, decimals(3) style(html) title(Crude and adjusted estimates of ///
        the effect of *smoke* and *ht* on both primary outcome (*bwt*) and ///
        secondary outcomes (*bwlt2500*, *bwlt1500*) )
Crude (Adjustment 1) and adjusted (Adjustment 2: *age*, *ftv* and *ui*) estimates of the effect of *smoke' and *race* on both primary outcome (*bwt*) and secondary outcomes (*bwlt2500*, *bwlt1500*)
Adjustment 1 Adjustment 2
bLower 95% CIUpper 95% CI bLower 95% CIUpper 95% CI
birthweight(grams) smoked during pregnancy (No) 0.000 0.000 0.000 0.000 0.000 0.000
smoked during pregnancy (Yes) -282.659 -493.652 -71.667 -228.915 -436.279 -21.552
race(white) 0.000 0.000 0.000 0.000 0.000 0.000
race(black) -383.318 -694.806 -71.830 -374.901 -680.471 -69.332
race(other) -298.995 -523.283 -74.708 -246.460 -468.551 -24.369
birthweight<2500g smoked during pregnancy (No) 0.000 0.000 0.000 0.000 0.000 0.000
smoked during pregnancy (Yes) 0.704 0.076 1.332 0.600 -0.060 1.259
race(white) 0.000 0.000 0.000 0.000 0.000 0.000
race(black) 0.845 -0.066 1.755 0.780 -0.183 1.743
race(other) 0.636 -0.047 1.320 0.497 -0.214 1.209
birthweight < 1500gsmoked during pregnancy (No) 0.000 0.000 0.000 0.000 0.000 0.000
smoked during pregnancy (Yes) 0.036 -1.782 1.855 -0.045 -2.313 2.222
race(white) 0.000 0.000 0.000 0.000 0.000 0.000
race(black) 1.335 -1.479 4.149 1.106 -2.255 4.468
race(other) 1.494 -0.798 3.785 1.613 -1.311 4.537

The do file for this document

Last update: 2019-02-27, Stata version 15.1