NLSYSTEM Instruction |
NLSYSTEM( options ) start end list of FRMLS
Estimates a system of non-linear equations using either multivariate non-linear least squares (non-linear Seemingly Unrelated Regressions) or, with instrumental variables, generalized method of moments (non-linear 3SLS is a special case of this). Use SUR for linear seemingly unrelated regressions.
Parameters
start, end |
the estimation range |
list of FRMLS |
The list of the formulas you want to estimate. A formula can define the residuals \({u_t}\) either as \({y_t} = f\left( {{{\bf{X}}_t},\theta } \right) + {u_t}\) or as \(f\left( {{{\bf{X}}_t},\theta } \right) = {u_t}\). NLSYSTEM assumes the first if you define the formula with a dependent variable and the second if you don’t. Please note that unlike NLLS, you can only indicate the dependent variable of a formula when you define the formula—there is no way to do it on the NLSYSTEM instruction. |
Description
NLSYSTEM uses one of two techniques:
•Multivariate non-linear least squares (non-linear SURE) when you estimate without instruments.
•Generalized Method of Moments for instrumental variables estimation. Non-linear three-stage least squares is a special case of this.
It does not do Maximum Likelihood estimation (except when these other techniques are equivalent to ML).
Before you can use NLSYSTEM, you must:
•Set the list of free parameters using NONLIN
•Create the explanatory formula f using FRML
•Set initial values for the parameters (usually with COMPUTE or INPUT)
If you have a linear system, the instruction SUR may be a better alternative. It is much faster at any type of model which both instructions can estimate.
Technical Information
(1) \({{\bf{u}}_t} = {\left( {{u_{1t}}, \ldots ,{u_{nt}}} \right)^\prime }\)
is the vector of residuals at time t (\(\bf{u}\) depends upon \(\theta\)), and
(2) \(\Sigma = E{{\bf{u}}_t}{{\bf{u}'_t}}\)
Multivariate non-linear least squares solves
(3) \(\mathop {\min }\limits_\theta \sum\limits_t {{{{\bf{u}'_t}}}{\kern 1pt} {\kern 1pt} {\Sigma ^{ - 1}}{\kern 1pt} {{\bf{u}}_t}} \)
For instrumental variables, further define
(4) \({{\bf{Z}}_t} = {\left( {{z_{1t}},{\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} \ldots {\kern 1pt} {\kern 1pt} {\kern 1pt} ,{z_{rt}}} \right)^\prime }\) as the vector of instruments at t, and
(5) \({\bf{G}}\left( \theta \right) = \sum\limits_t {{{\bf{u}}_t} \otimes {{\bf{Z}}_t}} \)
then Generalized Method of Moments solves
(6) \(\mathop {\min }\limits_\theta \;{\bf{G}}{\left( \theta \right)^\prime }\left[ {{\bf{SW}}} \right]\;{\bf{G}}\left( \theta \right)\)
where \({{\bf{SW}}}\) is the weighting matrix for the orthogonality conditions. Some of the options of NLSYSTEM let you set the form for the matrix \({{\bf{SW}}}\) in formula (6). By default, it is just \({\Sigma ^{ - 1}} \otimes {\left( {{\bf{Z'Z}}} \right)^{ - 1}}\), where \(\bf{Z}\) is the \(T \times r\) matrix of instruments for the entire sample. With this, NLSYSTEM does non-linear three stage least squares.
General Options
MODEL=MODEL to estimate [unused]
FRMLVECT=FRML[VECTOR] to be estimated
As an alternative to listing the formulas to be estimated as parameters, you can use the MODEL option to estimate an existing MODEL, or use FRMLVECT to provide a single FRML which, at each entry, provides the residuals in a VECTOR form. If you use MODEL, the MODEL must consist only of FRML’s.
PARMSET=PARMSET to use [default internal]
This option selects the PARMSET (parameter set) to be estimated. RATS maintains a single unnamed parameter set which is the one used for estimation if you don’t use PARMSET to specify a named set.
ITERATIONS=iteration limit [100]
SUBITERATIONS=subiteration limit [30]
CVCRIT=convergence limit [.00001]
TRACE/[NOTRACE]
ITERATIONS sets the maximum number of iterations, SUBITERS sets the maximum number of subiterations, CVCRIT the convergence criterion. TRACE prints the intermediate results. Note that the “function value” information when you use TRACE is not particularly useful. The objective function actually changes from one iteration to the next as the “nuisance parameters” (the \(\Sigma\) or weight matrix) are re-estimated.
STARTUP=FRML evaluated at period "start"
ONLYIF=expression tested before calculating start option [not used]
You can use the START option to provide an expression which is computed once per function evaluation, before any of the regular formulas are computed. This allows you to do any time-consuming calculations that depend upon the parameters, but not upon time. It can be an expression of any type. ONLYIF calculates the expression provided; if it evaluates to a zero value, the function evaluation doesn’t continue, and the function is assigned the missing value. ONLYIF is examined before doing START, unlike REJECT (below), which is done after the START.
REJECT=FRML indicating a “rejection” zone for the parameters
If the FRML evaluates to a non-zero (“true”) value, the function is immediately assigned the missing value.
SMPL=Standard SMPL option [unused]
[PRINT]/NOPRINT
VCV/[NOVCV]
TITLE="title for output" [depends upon options]
These are the standard output control options.
SIGMA/[NOSIGMA]
This controls the printing of the final estimate of the residual covariance matrix.
RESIDUALS=(output) VECTOR[SERIES] for residuals
This is the most convenient way to get the residuals. RESIDUALS=RESVAR will create series RESVAR(1),...,RESVAR(n) which will have the residuals from the n equations in the system.
DERIVES=(output) RECTANGULAR[SERIES] for partial derivatives [unused]
This saves the series of partial derivatives. The columns in the matrix correspond to the different sets of residuals. Thus the series in row one, column one of the array will be the partials with respect to the first parameter displayed in the output for the first residual. The series in row two, column one will the partials with respect to the second parameter for the first residual, and so on.
This saves the series of partial derivatives, with the columns in the matrix corresponding to the different sets of residuals.
CV=Input Sigma matrix
CVOUT=Output Sigma matrix
CV allows you to feed in an initial covariance matrix, and CVOUT allows you to store the final estimate of the covariance matrix. When you use CV, the standard errors and covariance matrix of coefficients will be correct only if the CV matrix incorporates the residual variances or if you use the option ROBUSTERRORS. These options were called ISIGMA and OUTSIGMA, respectively, prior to version 7.
Options for Multivariate Least Squares
JACOBIAN=FRML for the Jacobian
This option allows you to specify a FRML for the determinant of the Jacobian, for doing full-information maximum likelihood.
ROBUSTERRORS/[NOROBUSTERRORS]
LAGS=correlated lags [0]
LWINDOW=NEWEYWEST/BARTLETT/DAMPED/PARZEN/QUADRATIC/[FLAT]/PANEL/WHITE
LWFORM=VECTOR with the window form [not used]
CLUSTER=series with category values for clustered standard errors [not used]
DAMP=value of \(\gamma\) for LWINDOW=DAMPED [0.0]
When used without the INSTRUMENTS option, these permit calculation of a consistent covariance matrix allowing for heteroscedasticity (with ROBUSTERRORS) or serial correlation (with LAGS), or clustering based upon some other set of categories. Note that these have no effects on the point estimates.
Options for Instrumental Variables
Given a set of instruments, there is a different Generalized Method of Moments estimator for each choice of the weighting matrix \({{\mathbf{SW}}}\) (except if the model is just identified—then all choices of \({{\mathbf{SW}}}\) will give the same estimates). NLSYSTEM treats as a special case those situations where the SW matrix can be written in the form \({\Sigma ^{ - 1}} \otimes {\left( {{\bf{Z'Z}}} \right)^{ - 1}}\) . Note that \({{\bf{SW}}}\) is an \(nr \times nr\) matrix where n is the number of equations and r the number of instruments.
INSTRUMENTS/[NOINSTRUMENTS]
Use the INST option if you want to do instrumental variables estimation. Be sure to construct the instruments list in advance using the INSTRUMENTS instruction.
[ZUDEP]/NOZUDEP
WMATRIX=SYMMETRIC weighting matrix for instruments [\({\left( {{\bf{Z'Z}}} \right)^{ - 1}}\)]
IWMATRIX=SYMMETRIC inverse weighting matrix [not used]
SW=input SYMMETRIC grand weighting matrix [unused]
ISW=SYMMETRIC inverse grand weighting matrix
SWOUT=(output) estimated grand weighting matrix [unused]
NOZUDEP (the default) is the special case for the \({{\bf{SW}}}\) matrix. We call it NOZUDEP because the most important case is where u is (serially uncorrelated and) independent of the instruments \({{\bf{Z}}}\). More generally, this is Case (i) in Hansen(1982).
With NOZUDEP, you can use the WMATRIX or IWMATRIX option (whichever is more convenient) to set the W part of the \({\Sigma ^{ - 1}} \otimes {\bf{W}}\) and the CV option to set \(\Sigma\). Otherwise, NLSYSTEM estimates a new \(\Sigma\) after each iteration. Note that, if you use the LAGS option, NLSYSTEM will automatically switch to the ZUDEP method of handling the weight matrix.
If ZUDEP, you can use the SW or ISW option to set the full \({{\bf{SW}}}\) array. This is an \(nr \times nr\) SYMMETRIC array. Otherwise, NLSYSTEM determines a new \({{\bf{SW}}}\) matrix after each iteration by taking the inverse of
(7) \(\frac{1}{T}\sum {\left( {{{\bf{u}}_t} \otimes {{\bf{Z}}_t}} \right){{\left( {{{\bf{u}}_t} \otimes {{\bf{Z}}_t}} \right)}^\prime }} \)
(or the generalization of this if you use the LAGS option). The SWOUT option allows you to save the estimated SW matrix into the specified array.
UPDATE=NONE/ONCE/CONTINUOUS [default depends on other options]
This controls the updating of the weighting matrix. The default is normally UPDATE=CONTINUOUS, which recalculates the weight matrix at each iteration, except in the following cases:
•If you use the SW or ISW option, the default is UPDATE=NONE.
•If you use the CV option with NOZUDEP, the default is UPDATE=ONCE.
This option replaces the SECONDSTEP option used before version 7.
LAGS=correlated lags [0]
LWINDOW=NEWEYWEST/BARTLETT/DAMPED/PARZEN/QUADRATIC/[FLAT]/PANEL/WHITE
DAMP=value of \(\gamma\) for LWINDOW=DAMPED [0.0]
LWFORM=VECTOR with the lag window form [not used]
CLUSTER=SERIES with category values for clustered calculation
Use LAGS or LWINDOW=PANEL or the CLUSTER option to handle serial correlation in the \({\bf{u}} \otimes {\bf{Z}}\) process. Note that, unlike NLSYSTEM without INSTRUMENTS, these options do affect the estimated coefficients by changing the weight matrix.
ROBUSTERRORS/[NOROBUSTERRORS]
If you use ROBUSTERRORS combined with an input CV or SW matrix, NLSYSTEM will compute the coefficients using the “suboptimal” weighting matrix and then correct the covariance matrix of the coefficients based upon the choices for the LAGS, LWINDOW and other options immediately above.
JROBUST=STATISTIC/[DISTRIBUTION]
You can use this option to adjust the J-statistic specification test when the weighting matrix used is not the optimal one.
ZUMEAN=VECTOR of means of moment conditions [zeros]
This allows you to supply a VECTOR (with dimensions equal to the number of instruments) with a set of known (non-zero) means for the expected value of \({\bf{u}} \otimes {\bf{Z}}\). By default, RATS sets these to zero.
CENTER/[NOCENTER]
CENTER adjusts the formula for the weight matrix to subtract off the (sample) means of \({\bf{u}} \otimes {\bf{Z}}\), which may be non-zero for an overidentified model.
MASK=RECTANGULAR masking array for instruments [unused]
Normally, NLSYSTEM uses the same set of instruments (those listed on the INSTRUMENTS instruction) for all equations. MASK allows you to use different sets of instruments for some or all of the equations in your system.
You supply a RECTANGULAR array with dimensions “number of instruments” by “number of formulas,” so that each column corresponds to a formula (in the order listed on the NLSYSTEM instruction), and each row corresponds to one of the instruments (in the order listed on the INSTRUMENTS instruction).
To apply a particular instrument to a given formula, set the corresponding element of the MASK array to a non-zero value, such as 1. To exclude an instrument from a formula, set the appropriate entry to 0.
Variables Defined
%XX |
estimated covariance matrix of coefficients (SYMMETRIC) |
%BETA |
estimated coefficients (VECTOR) |
%TSTATS |
VECTOR with the t-stats for the coefficients |
%STDERRORS |
VECTOR of coefficient standard errors |
%NREG |
number of regressors (INTEGER) |
%NOBS |
number of observations (INTEGER) |
%NVAR |
number of equations (INTEGER) |
%NFREE |
number of free parameters (including estimated covariance matrix) (INTEGER) |
%LOGDET |
log determinant of the estimate of S (REAL) |
%SIGMA |
final covariance matrix of the residuals (SYMMETRIC) |
%ITERS |
iterations completed (INTEGER) |
%CONVERGED |
=1 or 0. 1 indicates that the process converged. (INTEGER) |
%CVCRIT |
final convergence criterion (REAL). This will be equal to zero if the sub-iteration limit was reached on the last iteration. |
%LAGRANGE |
VECTOR of Lagrange multipliers if estimating with constraints. |
Variables Defined (for Multivariate Least Squares)
%LOGL |
normal log likelihood (REAL) |
Variables Defined (for Instrumental Variables)
%JSTAT |
test statistics for overidentification (for instrumental variables regressions) (REAL) |
%JSIGNIF |
significance level of %JSTAT (REAL) |
%NDFJ |
degrees of freedom for %JSTAT (INTEGER) |
%UZWZU |
criterion function for instrumental variables/GMM (REAL) |
Examples
open data tablef6-2.csv
data(format=prn,org=columns) 1 159 firm year cost output $
lprice lshare kprice kshare fprice fshare
*
set logc = log(cost)
set logq = log(output)
set logpk = log(kprice)
set logpl = log(lprice)
set logpf = log(fprice)
*
* System without quadratic term
* For convenience, the formula is written in terms of all the beta's,
* with a substitution constraint which imposes the constant returns
* restriction.
*
nonlin b0 bq bk bl bf bf=1-bk-bl
frml costfnc logc = b0+bq*logq+bk*logpk+bl*logpl+bf*logpf
frml laborfnc lshare = bl
frml capfnc kshare = bk
nlsystem(title="Univariate (OLS)") / costfnc
nlsystem(title="Multivariate") / costfnc laborfnc capfnc
*
* System with quadratic term
*
nonlin b0 bq bqq bk bl bf bf=1-bk-bl
frml costfnc logc = b0+bq*logq+bqq*logq^2+bk*logpk+bl*logpl+bf*logpf
nlsystem(title="Univariate (OLS)") / costfnc
nlsystem(title="Multivariate") / costfnc laborfnc capfnc
This estimates a cost function by multivariate non-linear least squares. It also uses NLSYSTEM to estimate a single equation—that will produce the same results as NLLS, but has a slightly different setup.
calendar(m) 1946:1
open data tbills.xls
data(format=xls,org=columns) 1946:01 2011:01 tb3ms
*
set y1 = tb3ms
nonlin alpha beta gamma sigmasq
frml eps = y1{-1}-(1+beta)*y1-alpha
frml variance = eps(t)^2-sigmasq*y1^(2*gamma)
*
* Just identified model
*
instruments constant y1
nlsystem(instruments) / eps variance
*
* Overidentified model
*
* With nozudep
*
instruments constant y1{0 1}
nlsystem(instruments) / eps variance
*
* With ZUDEP
*
instruments constant y1{0 1}
nlsystem(instruments,zudep) / eps variance
This estimates a two-condition model (matching the mean and variance) by GMM. The first is just identified, using four moment conditions (two instruments x two residuals) to estimate four parameters. The second and third are overidentified, where the first uses NOZUDEP (the default) and the second uses ZUDEP.
Sample Output
This is the final multivariate NLSYSTEM from the first example. Overall information is listed in the header followed by blocks of statistics on the individual equations. The coefficient estimates come at the end since they can be (and here are) not necessarily specific to any one equations.
A common question is why there is no R^2 in the individual equation output. Because the sum of squared residuals aren't being minimized on an equation by equation basis, the R^2 would not be meaningful.
Multivariate
Convergence in 15 Iterations. Final criterion was 0.0000057 <= 0.0000100
Usable Observations 159
Log Likelihood 359.5223
Dependent Variable LOGC
Mean of Dependent Variable 1.8356603816
Std Error of Dependent Variable 1.4413223910
Standard Error of Estimate 0.3262739246
Sum of Squared Residuals 16.926293143
Durbin-Watson Statistic 1.5307
Dependent Variable LSHARE
Mean of Dependent Variable 0.1057798742
Std Error of Dependent Variable 0.0447008521
Standard Error of Estimate 0.0445612863
Sum of Squared Residuals 0.3157276089
Durbin-Watson Statistic 0.9242
Dependent Variable KSHARE
Mean of Dependent Variable 0.4268364780
Std Error of Dependent Variable 0.1164632388
Standard Error of Estimate 0.1161629387
Sum of Squared Residuals 2.1455187031
Durbin-Watson Statistic 2.0315
Variable Coeff Std Error T-Stat Signif
***************************************************************************************
1. B0 -5.915984949 0.156358697 -37.83598 0.00000000
2. BQ 0.296250844 0.054669753 5.41892 0.00000006
3. BQQ 0.041539139 0.004656861 8.91999 0.00000000
4. BK 0.422906017 0.009123377 46.35411 0.00000000
5. BL 0.105449510 0.003530057 29.87190 0.00000000
6. BF 0.471644473 0.000000000 0.00000 0.00000000
This is the output from the final (ZUDEP) estimator in the second example. All the header information is for the system as a whole since there are no obvious equations by equation statistics. The "J-Specification test" and the "Significance Level of J" will be present only if the model is overidentified.
GMM-Continuously Updated Weight Matrix
Convergence in 6 Iterations. Final criterion was 0.0000019 <= 0.0000100
Monthly Data From 1946:01 To 1959:03
Usable Observations 157
Skipped/Missing (from 159) 2
Function Value 5.62327864
J-Specification(2) 5.6233
Significance Level of J 0.0601064
Variable Coeff Std Error T-Stat Signif
***************************************************************************************
1. ALPHA 0.029062990 0.023032483 1.26183 0.20701134
2. BETA -0.005649855 0.015689771 -0.36010 0.71877385
3. GAMMA 0.219389985 0.307011677 0.71460 0.47485737
4. SIGMASQ 0.012713998 0.005785962 2.19739 0.02799282
Copyright © 2025 Thomas A. Doan