## Stata 15 help for matscore

```
[P] matrix score -- Score data from coefficient vectors

Syntax

matrix score [type] newvar = b [if] [in] [, equation(##|eqname)
missval(#) replace forcezero]

where b is a 1 x p matrix.

Description

matrix score creates newvar = x_jb' (b being a row vector), where x_j is
the row vector of values of the variables specified by the column names
of b.  The name _cons is treated as a variable equal to 1.

Options

equation(##|eqname) specifies the equation -- by either number or name --
for selecting coefficients from b to use in scoring. See [P] matrix
rownames for more on equation labels with matrices.

missval(#) specifies the value to be assumed if any values are missing
from the variables referred to by the coefficient vector.  By
default, this value is taken to be missing (.), and any missing value
among the variables produces a missing score.

replace specifies that newvar already exists. Here observations not
included by if exp and in range are left unchanged; that is, they are
not changed to missing.  Be warned that replace does not promote the
storage type of the existing variable; if the variable was stored as
an int, the calculated scores would be truncated to integers when
stored.

forcezero specifies that, should a variable described by the column names
of b not exist, the calculation treat the missing variable as if it
did exist and was equal to zero for all observations.  It contributes
nothing to the summation.  By default, a missing variable would
produce an error message.

Example

Setup
. sysuse auto
. regress price weight mpg

Define matrix coefs equal to e(b), the coefficient vector
. matrix coefs = e(b)

List the contents of coefs
. mat list coefs

Create variable lc containing the linear predictions
. matrix score lc = coefs

Summarize lc
. summarize lc

Setup
. sureg (price weight mpg) (displacement weight)

Define matrix coefs equal to e(b), the coefficient vector
. matrix coefs = e(b)

List the contents of coefs
. mat list coefs

Create variable lca containing the linear predictions for equation price
. matrix score lca = coefs, eq(price)

Same as above command
. matrix score lc1 = coefs, eq(#1)

Same as above command
. matrix score lcnoeq = coefs

Create variable lcb containing the linear predictions for equation
displacement
. matrix score lcb = coefs, eq(displacement)

Same as above command
. matrix score lc2 = coefs, eq(#2)

Summarize newly created variables
. summarize lc*

```