# 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

**outcomes**(varlist): A non-empty varlist of outcome variables. An outcome is the dependent variable in a regression.**exposures**(varlist): A non-empty varlist of outcome variables. Exposures are variables of whiech estimates are to be reported.**adjustments**(string): A set of varlist strings. A varlist string is a possibly empty set of adjustment variables. Each varlist string is surrounded in text quotes ("). An empty string ("") means no adjustment. Adjustment variables are variables needed for the estimation of the exposures, but it is not necessary to report their estimates.**noquietly**: If set, regression outputs are printed in the log.**labels**: Use variable and value labels.**base**: Include base values at factor variables.**keep**: To style output choose which calculations to keep. Choices are: b(=estimate of exposure in regression), se(=Se(estimate)), ci(=Confidence interval - level is set with set level), and p(=P-value).**drop**: To style output choose which calculations to drop. Choices are: b(=estimate of exposure in regression), se(=Se(estimate)), ci(=Confidence interval - level is set with set level), and p(=P-value).

## Stored results

-regmat- stores the following in r():

**local**

**r(Adjustment_#)**Adjustment number #.

**Matrix**

**r(regmat)**The matrix containing regression estimates of the exposures

## 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*

Columns by: smoked during pregnancy | No | Yes | Total | P-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*.

Columns by: race | white | black | other | Total | P-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
```

Adjustment 1 | Adjustment 2 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|

b | se(b) | Lower 95% CI | Upper 95% CI | P value | b | se(b) | Lower 95% CI | Upper 95% CI | P value | ||

bwt | smoke(1) | -282.66 | 106.95 | -493.65 | -71.67 | 0.01 | -228.92 | 105.10 | -436.28 | -21.55 | 0.03 |

race(2) | -383.32 | 157.89 | -694.81 | -71.83 | 0.02 | -374.90 | 154.86 | -680.47 | -69.33 | 0.02 | |

race(3) | -299.00 | 113.69 | -523.28 | -74.71 | 0.01 | -246.46 | 112.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
```

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.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
```

Adjustment 1 | Adjustment 2 | ||||||
---|---|---|---|---|---|---|---|

b | Lower 95% CI | Upper 95% CI | b | Lower 95% CI | Upper 95% CI | ||

birthweight<2500g | smoked during pregnancy (No) | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 |

smoked during pregnancy (Yes) | 2.02 | 1.08 | 3.79 | 1.82 | 0.94 | 3.52 | |

race(white) | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | |

race(black) | 2.33 | 0.94 | 5.79 | 2.18 | 0.83 | 5.71 | |

race(other) | 1.89 | 0.95 | 3.74 | 1.64 | 0.81 | 3.35 | |

birthweight < 1500g | smoked during pregnancy (No) | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 |

smoked during pregnancy (Yes) | 1.04 | 0.17 | 6.39 | 0.96 | 0.10 | 9.23 | |

race(white) | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | |

race(black) | 3.80 | 0.23 | 63.37 | 3.02 | 0.10 | 87.14 | |

race(other) | 4.45 | 0.45 | 44.03 | 5.02 | 0.27 | 93.42 |

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*) )
```

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 | |

birthweight<2500g | smoked during pregnancy (No) | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |

smoked during pregnancy (Yes) | 2.022 | 1.079 | 3.789 | 1.821 | 0.942 | 3.523 | |

race(white) | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | |

race(black) | 2.328 | 0.936 | 5.786 | 2.181 | 0.833 | 5.714 | |

race(other) | 1.889 | 0.954 | 3.742 | 1.644 | 0.807 | 3.350 | |

birthweight < 1500g | smoked during pregnancy (No) | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |

smoked during pregnancy (Yes) | 1.037 | 0.168 | 6.390 | 0.956 | 0.099 | 9.230 | |

race(white) | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | |

race(black) | 3.800 | 0.228 | 63.374 | 3.022 | 0.105 | 87.143 | |

race(other) | 4.453 | 0.450 | 44.033 | 5.017 | 0.269 | 93.425 |

Last update: 2018-11-16, Stata version 15.1