help mata mm_wbal()

Title

mm_wbal() -- Generate balancing weights using entropy balancing

Syntax

real rowvector
mm_wbal(X, w, Xref, wref [, nowarn])

where

X is the data to be reweighted; rows are observations, columns
are variables

w is a column vector containing base weights; use
w = 1 for unweighted data; if not scalar, w must have
the same number of rows as X

Xref is the reference data; rows are observations, columns
are variables; Xref must have the same number of columns as X;
if Xref only has a single row, it is assumed to contain population
averages

wref is a column vector containing base weights for the reference data; use
wref = 1 for unweighted data; if not scalar, wref must have
the same number of rows as Xref; if Xref only has a single row,
wref is assumed to contain the population size

nowarn!=0 suppresses the warning messages that are displayed
if convergence or balancing is not achieved. Omitted nowarn is
equivalent to nowarn=0.

Description

mm_wbal() returns a vector of balancing weights obtained by
entropy balancing. mm_wbal() is implemented
as a wrapper for mm_ebalance(). See the help file
of mm_ebalance() for technical details and
references.

Examples

Balance subsamples

. sysuse nlsw88, clear
. drop if missing(union, hours, ttl_exp, tenure)
. generate byte nonunion = 1 - union
. mata:
: X = st_data(., "hours ttl_exp tenure", "union")
: Xref = st_data(., "hours ttl_exp tenure", "nonunion")
: wbal = mm_wbal(X, 1, Xref, 1)
: mean(Xref)', mean(X)', mean(X, wbal)'
: rows(Xref), rows(X), sum(wbal)
: end

The balancing weights adjust the sample of unionized workers in a
way such that the means of working hours, work experience, and tenure are
the same as in the reference sample (non-unionized workers).

The sum of the balancing weights is equal to the size of the reference sample.

Adjust sample to population

From census data you know that the population averages of working hours,
work experience, and tenure are 35, 10, and 5, respectively. The size of the
population is 1 million. You want to reweight your sample such that
it is in line with the population:

. sysuse nlsw88, clear
. drop if missing(hours, ttl_exp, tenure)
. mata:
: X = st_data(., "hours ttl_exp tenure")
: mu = (35, 10, 5)
: N = 1e6
: wbal = mm_wbal(X, 1, mu, N)
: mean(X)', mean(X, wbal)'
: sum(wbal)
: end

Source code

mm_wbal.mata

Author

Ben Jann, University of Bern, ben.jann@unibe.ch

Also see

Online: help for
moremata, mm_ebalance()