//OFF
if `c(version)' >= 13 cls
use "lbw.dta", clear
//ON
/***
# 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](../../My%20commands/log2markup/log2markup_demo/) 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).
[To see -matprint- options](../../My%20commands/matprint/matprint_demo/)
## 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](https://books.google.dk/books/about/Applied_logistic_regression.html?id=-p5qAAAAMAAJ&redir_esc=y)
and the description from [Rachel MacKay Altman's old homepage](http://www.stat.sfu.ca/~raltman/stat300/DataSet5.doc)
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.
The goal of this study was to identify risk factors associated with giving
birth to a low birth weight baby (weighing less than 2500 grams).
Data were collected on 189 women, 59 of whom had low birth weight babies and
130 of whom had normal birth weight babies.
The observed predictor variables have been shown to be associated with low
birth weight in the obstetrical literature.
The goal of the current study was to ascertain if these variables were
important in the population being served by the medical centre where the data
were collected.
## 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 bwlt* no_yes
/***
## The Analysis
Crude estimates as well as estimates adjusted for *ftv* and *ptl* of the effect
of *smoke* and *age* on the two 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 age) ///
adjustments("" "ftv i.ptl"): logit, vce(robust) or
/***
The return list contains the adjustments and the estimates in a matrix.
***/
return list
/***
The estimates in the matrix looks like:
***/
matprint r(regmat), decimals(3)
/***
If options *labels* and *base* are added:
***/
regmat, outcome(bwlt2500 bwlt1500) exposure(i.smoke age) ///
adjustments("" "ftv i.ptl") labels base: logit, vce(robust) or
/***
The variable **smoke** has no value label:
***/
metadata
/***
By adding value labels to smoke and roping se and pvalue the returned matrix
becomes nicer to look at:
***/
label values smoke no_yes
regmat, outcome(bwlt2500 bwlt1500) exposure(i.smoke age) ///
adjustments("" "ftv i.ptl") labels base drop(se p): logit, vce(robust) or