Title
stata.com
nlcom — Nonlinear combinations of estimators
Syntax
Remarks and examples
Also see
Menu
Stored results
Description
Methods and formulas
Options
References
Syntax
Nonlinear combination of estimators—one expression
nlcom name: exp , options
Nonlinear combinations of estimators—more than one expression
nlcom ( name: exp) ( name: exp , options
options
Description
level(#)
iterate(#)
post
display options
set confidence level; default is level(95)
maximum number of iterations
post estimation results
control column formats and line width
noheader
df(#)
suppress output header
use t distribution with # degrees of freedom for computing p-values
and confidence intervals
noheader and df(#) do not appear in the dialog box.
The second syntax means that if more than one expression is specified, each must be surrounded by
parentheses. The optional name is any valid Stata name and labels the transformations.
exp is a possibly nonlinear expression containing
b[coef ]
b[eqno:coef ]
[eqno]coef
[eqno] b[coef ]
eqno is
##
name
coef identifies a coefficient in the model. coef is typically a variable name, a level indicator, an
interaction indicator, or an interaction involving continuous variables. Level indicators identify one
level of a factor variable and interaction indicators identify one combination of levels of an interaction;
see [U] 11.4.3 Factor variables. coef may contain time-series operators; see [U] 11.4.4 Time-series
varlists.
Distinguish between [ ], which are to be typed, and
, which indicate optional arguments.
1
2
nlcom — Nonlinear combinations of estimators
Menu
Statistics
>
Postestimation
>
Nonlinear combinations of estimates
Description
nlcom computes point estimates, standard errors, test statistics, significance levels, and confidence
intervals for (possibly) nonlinear combinations of parameter estimates after any Stata estimation
command. Results are displayed in the usual table format used for displaying estimation results.
Calculations are based on the “delta method”, an approximation appropriate in large samples.
nlcom can be used with svy estimation results; see [SVY] svy postestimation.
Options
level(#) specifies the confidence level, as a percentage, for confidence intervals. The default is
level(95) or as set by set level; see [U] 20.7 Specifying the width of confidence intervals.
iterate(#) specifies the maximum number of iterations used to find the optimal step size in
calculating numerical derivatives of the transformation(s) with respect to the original parameters.
By default, the maximum number of iterations is 100, but convergence is usually achieved after
only a few iterations. You should rarely have to use this option.
post causes nlcom to behave like a Stata estimation (eclass) command. When post is specified,
nlcom will post the vector of transformed estimators and its estimated variance–covariance matrix to
e(). This option, in essence, makes the transformation permanent. Thus you could, after posting,
treat the transformed estimation results in the same way as you would treat results from other
Stata estimation commands. For example, after posting, you could redisplay the results by typing
nlcom without any arguments, or use test to perform simultaneous tests of hypotheses on linear
combinations of the transformed estimators; see [R] test.
Specifying post clears out the previous estimation results, which can be recovered only by refitting
the original model or by storing the estimation results before running nlcom and then restoring
them; see [R] estimates store.
display options: cformat(% fmt), pformat(% fmt), sformat(% fmt), and nolstretch; see [R] estimation options.
The following options are available with nlcom but are not shown in the dialog box:
noheader suppresses the output header.
df(#) specifies that the t distribution with # degrees of freedom be used for computing p-values and
confidence intervals.
Remarks and examples
Remarks are presented under the following headings:
Introduction
Basics
Using the post option
Reparameterizing ML estimators for univariate data
nlcom versus eform
stata.com
nlcom — Nonlinear combinations of estimators
3
Introduction
nlcom and predictnl both use the delta method. They take nonlinear transformations of the
estimated parameter vector from some fitted model and apply the delta method to calculate the variance,
standard error, Wald test statistic, etc., of the transformations. nlcom is designed for functions of the
parameters, and predictnl is designed for functions of the parameters and of the data, that is, for
predictions.
nlcom generalizes lincom (see [R] lincom) in two ways. First, nlcom allows the transformations
to be nonlinear. Second, nlcom can be used to simultaneously estimate many transformations (whether
linear or nonlinear) and to obtain the estimated variance–covariance matrix of these transformations.
Basics
In [R] lincom, the following regression was performed:
. use http://www.stata-press.com/data/r13/regress
. regress y x1 x2 x3
Source
SS
df
MS
Model
Residual
3259.3561
1627.56282
3
144
1086.45203
11.3025196
Total
4886.91892
147
33.2443464
y
Coef.
x1
x2
x3
_cons
1.457113
2.221682
-.006139
36.10135
Std. Err.
1.07461
.8610358
.0005543
4.382693
t
1.36
2.58
-11.08
8.24
P>|t|
0.177
0.011
0.000
0.000
Number of obs
F( 3,
144)
Prob > F
R-squared
Adj R-squared
Root MSE
=
=
=
=
=
=
148
96.12
0.0000
0.6670
0.6600
3.3619
[95% Conf. Interval]
-.666934
.5197797
-.0072345
27.43863
3.581161
3.923583
-.0050435
44.76407
Then lincom was used to estimate the difference between the coefficients of x1 and x2:
. lincom _b[x2] - _b[x1]
( 1) - x1 + x2 = 0
y
Coef.
(1)
.7645682
Std. Err.
t
P>|t|
[95% Conf. Interval]
.9950282
0.77
0.444
-1.20218
2.731316
It was noted, however, that nonlinear expressions are not allowed with lincom:
. lincom _b[x2]/_b[x1]
not possible with test
r(131);
Nonlinear transformations are instead estimated using nlcom:
. nlcom _b[x2]/_b[x1]
_nl_1: _b[x2]/_b[x1]
y
Coef.
_nl_1
1.524714
Std. Err.
z
P>|z|
.9812848
1.55
0.120
[95% Conf. Interval]
-.3985686
3.447997
4
nlcom — Nonlinear combinations of estimators
Technical note
The notation b[name] is the standard way in Stata to refer to regression coefficients; see
[U] 13.5 Accessing coefficients and standard errors. Some commands, such as lincom and test,
allow you to drop the b[] and just refer to the coefficients by name. nlcom, however, requires the
full specification b[name].
Returning to our linear regression example, nlcom also allows simultaneous estimation of more
than one combination:
. nlcom (_b[x2]/_b[x1]) (_b[x3]/_b[x1]) (_b[x3]/_b[x2])
_nl_1: _b[x2]/_b[x1]
_nl_2: _b[x3]/_b[x1]
_nl_3: _b[x3]/_b[x2]
y
Coef.
_nl_1
_nl_2
_nl_3
1.524714
-.0042131
-.0027632
Std. Err.
.9812848
.0033483
.0010695
z
1.55
-1.26
-2.58
P>|z|
0.120
0.208
0.010
[95% Conf. Interval]
-.3985686
-.0107756
-.0048594
3.447997
.0023494
-.000667
We can also label the transformations to produce more informative names in the estimation table:
. nlcom (ratio21:_b[x2]/_b[x1]) (ratio31:_b[x3]/_b[x1]) (ratio32:_b[x3]/_b[x2])
ratio21: _b[x2]/_b[x1]
ratio31: _b[x3]/_b[x1]
ratio32: _b[x3]/_b[x2]
y
Coef.
ratio21
ratio31
ratio32
1.524714
-.0042131
-.0027632
Std. Err.
.9812848
.0033483
.0010695
z
1.55
-1.26
-2.58
P>|z|
0.120
0.208
0.010
[95% Conf. Interval]
-.3985686
-.0107756
-.0048594
3.447997
.0023494
-.000667
nlcom stores the vector of estimated combinations and its estimated variance–covariance matrix
in r().
. matrix list r(b)
r(b)[1,3]
ratio21
ratio31
c1
1.5247143 -.00421315
. matrix list r(V)
symmetric r(V)[3,3]
ratio21
ratio21
.96291982
ratio31 -.00287781
ratio32 -.00014234
ratio32
-.00276324
ratio31
ratio32
.00001121
2.137e-06
1.144e-06
nlcom — Nonlinear combinations of estimators
5
Using the post option
When used with the post option, nlcom stores the estimation vector and variance–covariance
matrix in e(), making the transformation permanent:
. quietly nlcom (ratio21:_b[x2]/_b[x1]) (ratio31:_b[x3]/_b[x1])
> (ratio32:_b[x3]/_b[x2]), post
. matrix list e(b)
e(b)[1,3]
ratio21
ratio31
y1
1.5247143 -.00421315
. matrix list e(V)
symmetric e(V)[3,3]
ratio21
ratio21
.96291982
ratio31 -.00287781
ratio32 -.00014234
ratio32
-.00276324
ratio31
ratio32
.00001121
2.137e-06
1.144e-06
After posting, we can proceed as if we had just run a Stata estimation (eclass) command. For
instance, we can replay the results,
. nlcom
y
Coef.
ratio21
ratio31
ratio32
1.524714
-.0042131
-.0027632
Std. Err.
.9812848
.0033483
.0010695
z
1.55
-1.26
-2.58
P>|z|
0.120
0.208
0.010
[95% Conf. Interval]
-.3985686
-.0107756
-.0048594
3.447997
.0023494
-.000667
or perform other postestimation tasks in the transformed metric, this time making reference to the
new “coefficients”:
. display _b[ratio31]
-.00421315
. estat vce, correlation
Correlation matrix of coefficients of nlcom model
e(V)
ratio21
ratio21
1.0000
ratio31
-0.8759
ratio32
-0.1356
. test _b[ratio21] = 1
( 1) ratio21 = 1
chi2( 1) =
Prob > chi2 =
ratio31
ratio32
1.0000
0.5969
1.0000
0.29
0.5928
We see that testing b[ratio21]=1 in the transformed metric is equivalent to testing using testnl
b[x2]/ b[x1]=1 in the original metric:
. quietly regress y x1 x2 x3
. testnl _b[x2]/_b[x1] = 1
(1) _b[x2]/_b[x1] = 1
chi2(1) =
Prob > chi2 =
0.29
0.5928
We needed to refit the regression model to recover the original parameter estimates.
6
nlcom — Nonlinear combinations of estimators
Technical note
In a previous technical note, we mentioned that commands such as lincom and test permit
reference to name instead of b[name]. This is not the case when lincom and test are used after
nlcom, post. In the above, we used
. test _b[ratio21] = 1
rather than
. test ratio21 = 1
which would have returned an error. Consider this a limitation of Stata. For the shorthand notation
to work, you need a variable named name in the data. In nlcom, however, name is just a coefficient
label that does not necessarily correspond to any variable in the data.
Reparameterizing ML estimators for univariate data
When run using only a response and no covariates, Stata’s maximum likelihood (ML) estimation
commands will produce ML estimates of the parameters of some assumed univariate distribution for
the response. The parameterization, however, is usually not one we are used to dealing with in a
nonregression setting. In such cases, nlcom can be used to transform the estimation results from a
regression model to those from a maximum likelihood estimation of the parameters of a univariate
probability distribution in a more familiar metric.
Example 1
Consider the following univariate data on Y = # of traffic accidents at a certain intersection in a
given year:
. use http://www.stata-press.com/data/r13/trafint
. summarize accidents
Variable
Obs
Mean
Std. Dev.
accidents
12
13.83333
14.47778
Min
Max
0
41
A quick glance of the output from summarize leads us to quickly reject the assumption that Y is
distributed as Poisson because the estimated variance of Y is much greater than the estimated mean
of Y .
Instead, we choose to model the data as univariate negative binomial, of which a common
parameterization is
Pr(Y = y) =
Γ(r + y)
pr (1 − p)y
Γ(r)Γ(y + 1)
with
E(Y ) =
r(1 − p)
p
0 ≤ p ≤ 1,
Var(Y ) =
r > 0,
y = 0, 1, . . .
r(1 − p)
p2
There exist no closed-form solutions for the maximum likelihood estimates of p and r, yet they
may be estimated by the iterative method of Newton–Raphson. One way to get these estimates would
be to write our own Newton–Raphson program for the negative binomial. Another way would be to
write our own ML evaluator; see [R] ml.
nlcom — Nonlinear combinations of estimators
7
The easiest solution, however, would be to use Stata’s existing negative binomial ML regression command, nbreg. The only problem with this solution is that nbreg estimates a different
parameterization of the negative binomial, but we can worry about that later.
. nbreg accidents
Fitting Poisson model:
Iteration 0:
Iteration 1:
log likelihood = -105.05361
log likelihood = -105.05361
Fitting constant-only model:
Iteration
Iteration
Iteration
Iteration
0:
1:
2:
3:
log
log
log
log
likelihood
likelihood
likelihood
likelihood
= -43.948619
= -43.891483
= -43.89144
= -43.89144
Fitting full model:
Iteration 0:
Iteration 1:
log likelihood =
log likelihood =
-43.89144
-43.89144
Negative binomial regression
Number of obs
LR chi2(0)
Prob > chi2
Pseudo R2
Dispersion
= mean
Log likelihood = -43.89144
accidents
Coef.
_cons
=
=
=
=
12
0.00
.
0.0000
Std. Err.
z
P>|z|
[95% Conf. Interval]
2.627081
.3192233
8.23
0.000
2.001415
3.252747
/lnalpha
.1402425
.4187147
-.6804233
.9609083
alpha
1.150553
.4817534
.5064026
2.61407
Likelihood-ratio test of alpha=0:
chibar2(01) =
122.32 Prob>=chibar2 = 0.000
. nbreg, coeflegend
Negative binomial regression
Number of obs
LR chi2(0)
Prob > chi2
Pseudo R2
Dispersion
= mean
Log likelihood = -43.89144
accidents
Coef.
_cons
2.627081
_b[accidents:_cons]
/lnalpha
.1402425
_b[lnalpha:_cons]
alpha
1.150553
=
=
=
=
12
0.00
.
0.0000
Legend
Likelihood-ratio test of alpha=0:
chibar2(01) =
122.32 Prob>=chibar2 = 0.000
From this output, we see that, when used with univariate data, nbreg estimates a regression
intercept, β0 , and the logarithm of some parameter α. This parameterization is useful in regression
models: β0 is the intercept meant to be augmented with other terms of the linear predictor, and α is
an overdispersion parameter used for comparison with the Poisson regression model.
However, we need to transform (β0 , lnα) to (p, r). Examining Methods and formulas of [R] nbreg
reveals the transformation as
p = {1 + α exp(β0 )}−1
which we apply using nlcom:
r = α−1
8
nlcom — Nonlinear combinations of estimators
. nlcom (p:1/(1 + exp([lnalpha]_b[_cons] + _b[_cons])))
> (r:exp(-[lnalpha]_b[_cons]))
p: 1/(1 + exp([lnalpha]_b[_cons] + _b[_cons]))
r: exp(-[lnalpha]_b[_cons])
accidents
Coef.
p
r
.0591157
.8691474
Std. Err.
z
P>|z|
[95% Conf. Interval]
.0292857
.3639248
2.02
2.39
0.044
0.017
.0017168
.1558679
.1165146
1.582427
Given the invariance of maximum likelihood estimators and the properties of the delta method, the
above parameter estimates, standard errors, etc., are precisely those we would have obtained had we
instead performed the Newton–Raphson optimization in the (p, r) metric.
Technical note
Note how we referred to the estimate of lnα above as [lnalpha] b[ cons]. This is not entirely
evident from the output of nbreg, which is why we redisplayed the results using the coeflegend
option so that we would know how to refer to the coefficients; [U] 13.5 Accessing coefficients and
standard errors.
nlcom versus eform
Many Stata estimation commands allow you to display exponentiated regression coefficients, some
by default, some optionally. Known as “eform” in Stata terminology, this reparameterization serves
many uses: it gives odds ratios for logistic models, hazard ratios in survival models, incidence-rate
ratios in Poisson models, and relative-risk ratios in multinomial logit models, to name a few.
For example, consider the following estimation taken directly from the technical note in [R] poisson:
. use http://www.stata-press.com/data/r13/airline
. generate lnN = ln(n)
. poisson injuries XYZowned lnN
Iteration 0:
log likelihood = -22.333875
Iteration 1:
log likelihood = -22.332276
Iteration 2:
log likelihood = -22.332276
Poisson regression
Number of obs
LR chi2(2)
Prob > chi2
Log likelihood = -22.332276
Pseudo R2
injuries
Coef.
XYZowned
lnN
_cons
.6840667
1.424169
4.863891
Std. Err.
z
P>|z|
.3895877
.3725155
.7090501
1.76
3.82
6.86
0.079
0.000
0.000
=
=
=
=
9
19.15
0.0001
0.3001
[95% Conf. Interval]
-.0795111
.6940517
3.474178
1.447645
2.154285
6.253603
nlcom — Nonlinear combinations of estimators
9
When we replay results and specify the irr (incidence-rate ratios) option,
. poisson, irr
Poisson regression
Number of obs
LR chi2(2)
Prob > chi2
Pseudo R2
Log likelihood = -22.332276
injuries
IRR
XYZowned
lnN
_cons
1.981921
4.154402
129.5272
=
=
=
=
9
19.15
0.0001
0.3001
Std. Err.
z
P>|z|
[95% Conf. Interval]
.7721322
1.547579
91.84126
1.76
3.82
6.86
0.079
0.000
0.000
.9235678
2.00181
32.2713
4.253085
8.621728
519.8828
we obtain the exponentiated regression coefficients and their estimated standard errors.
Contrast this with what we obtain if we exponentiate the coefficients manually by using nlcom:
. nlcom (E_XYZowned:exp(_b[XYZowned])) (E_lnN:exp(_b[lnN]))
E_XYZowned: exp(_b[XYZowned])
E_lnN: exp(_b[lnN])
injuries
Coef.
E_XYZowned
E_lnN
1.981921
4.154402
Std. Err.
z
P>|z|
[95% Conf. Interval]
.7721322
1.547579
2.57
2.68
0.010
0.007
.4685701
1.121203
3.495273
7.187602
There are three things to note when comparing poisson, irr (and eform in general) with nlcom:
1. The exponentiated coefficients and standard errors are identical. This is certainly good news.
2. The Wald test statistic (z) and level of significance are different. When using poisson, irr and
other related eform options, the Wald test does not change from what you would have obtained
without the eform option, and you can see this by comparing both versions of the poisson output
given previously.
When you use eform, Stata knows that what is usually desired is a test of
H0 : exp(β) = 1
and not the uninformative-by-comparison
H0 : exp(β) = 0
The test of H0 : exp(β) = 1 is asymptotically equivalent to a test of H0 : β = 0, the Wald test in
the original metric, but the latter has better small-sample properties. Thus if you specify eform,
you get a test of H0 : β = 0.
nlcom, however, is general. It does not attempt to infer the test of greatest interest for a given
transformation, and so a test of
H0 : transformed coefficient = 0
is always given, regardless of the transformation.
3. You may be surprised to see that, even though the coefficients and standard errors are identical,
the confidence intervals (both 95%) are different.
10
nlcom — Nonlinear combinations of estimators
eform confidence intervals are standard confidence intervals with the endpoints transformed. For
example, the confidence interval for the coefficient on lnN is [0.694, 2.154], whereas the confidence
interval for the incidence-rate ratio due to lnN is [exp(0.694), exp(2.154)] = [2.002, 8.619], which,
except for some roundoff error, is what we see from the output of poisson, irr. For exponentiated
coefficients, confidence intervals based on transform-the-endpoints methodology generally have
better small-sample properties than their asymptotically equivalent counterparts.
The transform-the-endpoints method, however, gives valid coverage only when the transformation
is monotonic. nlcom uses a more general and asymptotically equivalent method for calculating
confidence intervals, as described in Methods and formulas.
Stored results
nlcom stores the following in r():
Scalars
r(N)
r(df r)
number of observations
residual degrees of freedom
Matrices
r(b)
r(V)
vector of transformed coefficients
estimated variance–covariance matrix of the transformed coefficients
If post is specified, nlcom also stores the following in e():
Scalars
e(N)
e(df r)
e(N strata)
e(N psu)
e(rank)
number
residual
number
number
rank of
of observations
degrees of freedom
of strata L, if used after svy
of sampled PSUs n, if used after svy
e(V)
Macros
e(cmd)
nlcom
e(predict)
program used to implement predict
e(properties) b V
Matrices
e(b)
e(V)
e(V srs)
e(V srswr)
e(V msp)
vector of transformed coefficients
estimated variance–covariance matrix of the transformed coefficients
bsrswor , if svy
simple-random-sampling-without-replacement (co)variance V
bsrswr , if svy and fpc()
simple-random-sampling-with-replacement (co)variance V
bmsp , if svy and available
misspecification (co)variance V
Functions
e(sample)
marks estimation sample
Methods and formulas
Given a 1 ×k vector of parameter estimates, b
θ = (θb1 , . . . , θbk ), consider the estimated p-dimensional
transformation
g(b
θ) = [g1 (b
θ), g2 (b
θ), . . . , gp (b
θ)]
The estimated variance–covariance of g(b
θ) is given by
n
o
c g(b
Var
θ) = GVG0
nlcom — Nonlinear combinations of estimators
where G is the p × k matrix of derivatives for which
∂gi (θ) i = 1, . . . , p
Gij =
∂θj θ=b
θ
11
j = 1, . . . , k
and V is the estimated variance–covariance matrix of b
θ. Standard errors are obtained as the square
roots of the variances.
The Wald test statistic for testing
H0 : gi (θ) = 0
versus the two-sided alternative is given by
Zi = h
gi (b
θ)
n
oi1/2
c ii g(b
Var
θ)
When the variance–covariance matrix of b
θ is an asymptotic covariance matrix, Zi is approximately
distributed as Gaussian. For linear regression, Zi is taken to be approximately distributed as t1,r
where r is the residual degrees of freedom from the original fitted model.
A (1 − α) × 100% confidence interval for gi (θ) is given by
h
n
oi1/2
c ii g(b
gi (b
θ) ± zα/2 Var
θ)
for those cases where Zi is Gaussian and
h
n
oi1/2
c ii g(b
gi (b
θ) ± tα/2,r Var
θ)
for those cases where Zi is t distributed. zp is the 1 − p quantile of the standard normal distribution,
and tp,r is the 1 − p quantile of the t distribution with r degrees of freedom.
References
Feiveson, A. H. 1999. FAQ: What is the delta method and how is it used to estimate the standard error of a
transformed parameter? http://www.stata.com/support/faqs/stat/deltam.html.
Gould, W. W. 1996. crc43: Wald test of nonlinear hypotheses after model estimation. Stata Technical Bulletin 29:
2–4. Reprinted in Stata Technical Bulletin Reprints, vol. 5, pp. 15–18. College Station, TX: Stata Press.
Oehlert, G. W. 1992. A note on the delta method. American Statistician 46: 27–29.
Phillips, P. C. B., and J. Y. Park. 1988. On the formulation of Wald tests of nonlinear restrictions. Econometrica 56:
1065–1083.
Also see
[R] lincom — Linear combinations of estimators
[R] predictnl — Obtain nonlinear predictions, standard errors, etc., after estimation
[R] test — Test linear hypotheses after estimation
[R] testnl — Test nonlinear hypotheses after estimation
[U] 20 Estimation and postestimation commands
© Copyright 2025 Paperzz