Examples / NONLINEAR.RPF |
NONLINEAR.RPF estimates the same model with a non-linearity in the dependent variable using several different techniques. It is adapted from Greene, Econometric Analysis, 5th Edition, example 17.5, pages 498-499. A production function takes the form:
\begin{equation} \log \,y_i + \theta y_i = \beta _1 + \beta _2 \log \,K_i + \beta _3 \log \,L_i + \varepsilon _i ,\varepsilon _i \sim N(0,\sigma ^2 )\,i.i.d. \end{equation}
which would be a standard Cobb-Douglas production function except for the \(\theta y_i \) term. Because of the transformation of the dependent variable, there’s a Jacobian term that must be included in the likelihood. The model can be estimated directly by MAXIMIZE, or by NLLS with the JACOBIAN option.
The example first does a simple non-linear least squares estimate, which is a poor choice when \(\theta\) is unknown.
nonlin b1 b2 b3 theta
compute b1=b2=b3=theta=0.0
*
frml resid = log(y)+theta*y-b1-b2*logk-b3*logl
nlls(frml=resid)
Proper estimates require adjusting for the Jacobian—the derivative of \(\log \,y_i + \theta y_i \) with respect to \(y_i\), which is \(\left( {1/y + \theta } \right)\). To do maximum likelihood directly, we need to add the (unknown) residual variance to the parameter set. Also, because the FRML for maximum likelihood is the log likelihood, we need the log of the Jacobian in addition to the log Normal density. Note that this is using the RESID function defined above, which computes the residual for a given entry given the parameters:
nonlin b1 b2 b3 theta sigsq
frml loglike = log(1/y+theta)+%logdensity(sigsq,resid)
We need to initialize sigsq to a positive number (almost any number will work) or loglike won't be computable at the initial guesses.
compute sigsq=%seesq
maximize(method=bfgs) loglike
NLLS with the JACOBIAN option can also be used for this (since this is just non-linear least squares on a transformed variable). You provide a formula that computes the Jacobian itself, and it takes care of the adjustment. (This has the advantage compared with MAXIMIZE that the variance is concentrated out):
nonlin b1 b2 b3 theta
nlls(jacobian=(1/y+theta),frml=resid)
An alternative is to observe that, given \(\theta\), all the other coefficients can be estimated by a least squares regression. This uses FIND to search for the maximum likelihood \(\theta\). The regression part of the likelihood is concentrated into the single value %LOGL which is then adjusted by the sum of the log Jacobians (computed using SSTATS). FIND controls a loop much as DO does. The instructions between FIND and END are executed each time a new function evaluation is needed.
dec real concentrate
nonlin theta
find maximum concentrate
set yadjust = log(y)+theta*y
linreg(noprint) yadjust
# constant logk logl
sstats / log(1/y+theta)>>yterms
compute concentrate=yterms+%logl
end find
Full Program
open data tablef9-2[1].txt
data(format=prn,org=columns) 1 25 valueadd capital labor nfirm
*
set y = valueadd/nfirm
set k = capital/nfirm
set l = labor/nfirm
set logk = log(k)
set logl = log(l)
*
* Nonlinear least squares (which is a poor estimator if theta is
* unknown). Because the "dependent variable" is actually a combination
* of two terms, we just define the formula as the residual. If NLLS sees
* a FRML without an explicitly defined dependent variable, it will just
* minimize the sum of squares of the frml itself.
*
nonlin b1 b2 b3 theta
compute b1=b2=b3=theta=0.0
*
frml resid = log(y)+theta*y-b1-b2*logk-b3*logl
nlls(frml=resid)
*************************************************************************
*
* Maximum likelihood estimates. We need to add the variance to the list
* of parameters (if we're doing a joint estimate of all the parameters).
* The log likelihood formula itself uses the resid FRML defined above as
* a building block so we don't have to repeat it.
*
nonlin b1 b2 b3 theta sigsq
frml loglike = log(1/y+theta)+%logdensity(sigsq,resid)
*
* We need to initialize sigsq to a positive number or loglike won't be
* computable at the initial guesses.
*
compute sigsq=%seesq
maximize(method=bfgs) loglike
*************************************************************************
*
* This is an alternative way to do maximum likelihood. This uses NLLS
* with the JACOBIAN option to take care of those terms in the likelihood.
*
nonlin b1 b2 b3 theta
nlls(jacobian=(1/y+theta),frml=resid)
*************************************************************************
*
* This is the same maximum likelihood done by concentrating out the
* beta's and variance, since given theta, the likelihood is just least
* squares.
*
dec real concentrate
nonlin theta
find maximum concentrate
set yadjust = log(y)+theta*y
linreg(noprint) yadjust
# constant logk logl
sstats / log(1/y+theta)>>yterms
compute concentrate=yterms+%logl
end find
Output
Nonlinear Least Squares - Estimation by Gauss-Newton
Convergence in 1 Iterations. Final criterion was 0.0000000 <= 0.0000100
Usable Observations 25
Degrees of Freedom 21
Standard Error of Estimate 0.1909311795
Sum of Squared Residuals 0.7655490214
Log Likelihood 8.1020
Durbin-Watson Statistic 2.0367
Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. B1 2.108924948 1.570598878 1.34275 0.17935226
2. B2 0.257900246 0.459701239 0.56102 0.57478589
3. B3 0.878387869 0.650499966 1.35033 0.17691102
4. THETA -0.031634242 0.251239073 -0.12591 0.89980086
MAXIMIZE - Estimation by BFGS
Convergence in 19 Iterations. Final criterion was 0.0000000 <= 0.0000100
Usable Observations 25
Function Value -8.9390
Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. B1 2.9146396083 0.3439594778 8.47379 0.00000000
2. B2 0.3500318252 0.0883948446 3.95987 0.00007499
3. B3 1.0922472883 0.1306105504 8.36263 0.00000000
4. THETA 0.1066386111 0.0560053532 1.90408 0.05689991
5. SIGSQ 0.0427381564 0.0152962742 2.79402 0.00520566
Nonlinear Least Squares - Estimation by Gauss-Newton
Convergence in 1 Iterations. Final criterion was 0.0000059 <= 0.0000100
Usable Observations 25
Degrees of Freedom 21
Standard Error of Estimate 0.2255750331
Sum of Squared Residuals 1.0685660063
Log Likelihood -8.9390
Durbin-Watson Statistic 1.5469
Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. B1 2.9148206024 1.0880209533 2.67901 0.00738399
2. B2 0.3500674182 0.2818202853 1.24217 0.21417553
3. B3 1.0922747920 0.4152567890 2.63036 0.00852945
4. THETA 0.1066652764 0.1773732820 0.60136 0.54759994
FIND Optimization - Estimation by Simplex
Function Value -8.9390
Variable Coeff
**********************************************
1. THETA 0.1066652764
Copyright © 2025 Thomas A. Doan