*! version 1.0.0 2025-11-30

Title

regoptwgt -- Optimal population weighting for regressions and instrumental variables

Syntax

regoptwgt depvar
[varlist1]
[(varlist2=varlist3)]
[w=weight_variable]
[if] [in]
[, options]

technique maximization technique; see maximize; default is nr bhhh dfp bfgs

iterate(#) perform maximum of # iterations; default is iterate(300)

cluster(varlist) cluster standard errors by varlist

robust this option has no effect; errors are always robust

jackknife estimate standard errors with a jackknife method; if used, only one cluster variable is allowed

difficult use a different stepping algorithm in nonconcave regions

mlsearch(#) if # is nonnegative, perform ml search, repeat(#) before maximization; default is to not do this

initnowgt unlike the default, do not initialize search at the parameter estimates for an unweighted regression

Description

regoptwgt estimates regression coefficients based on an optimal weighting that takes into account both
(1) variance in the error term that is correlated with the inverse of the weighting variable, and
(2) variance in the error term that is independent of the weighting variable.
Estimates are calculated using limited information maximum likelihood.

Remarks

regoptwgt uses similar syntax to commands regress, ivregress 2sls and other related commands.
It is therefore often possible to simply replace these commands with regoptwgt to get the optimally-weighted estimate.

regoptwgt estimates the equations requested, as well as extra parameters that measure the extent of heteroskedasticity correlated with the given weight.
lnetasq parameters measure the natural log of the estimated variance of the part of the error term that is correlated with the weight; lnnusq parameters measure the natural log of the estimated variance of the part of the error term that is NOT correlated with the weight.
fncorr parameters measure a monotonically increasing function of the correlation between the lnetasq and lnnusq parameters in each equation.
These parameters are described in more detail in the companion article, which will be released shortly.

regoptwgt works with any number of endogenous variables, but it is very slow if there are two or more right hand side endogenous variables.

Examples

Setup

. set seed 0

. clear

. set obs 100

. gen pop = 1/_n

. gen z = rnormal()

. gen xeta = rnormal()

. gen x = z + rnormal() + .1/sqrt(pop)*(xeta + rnormal())

. gen y = x + rnormal() + .1/sqrt(pop)*(xeta + rnormal())

Simple regression

. regoptwgt y z [w=pop]

Instrumental variables regression

. regoptwgt y (x=z) [w=pop]

Stored results

The final step of regoptwgt is a maximum likelihood estimation, so the command inherits stored results from ml maximize. This includes the following stored in e():

Scalars

e(N) number of observations

e(k) number of parameters

e(ll) log likelihood

Macros

e(depvar) names of dependent variables

Matrices

e(b) coefficient vector

e(V) variance-covariance matrix of the estimators

Author

David J. Price

david.price@utoronto.ca

davidjonathanprice.com

Citation

Please cite:

David J. Price (2025). Power Law Heteroskedasticity.

Acknowledgment

Multiway clustering uses vcemway.