* Nonlinear Regression for Cobb-Douglas Production Function
*
* Keywords:
* regression, nonlinear, r-squared, autocorrelation, dw, durbin-watson,
* test, cobb-douglas, production, funciton, mexico
*
* Description:
* We illustrate how to estimate a Nonlinear Exponential Model for Mexican
* Cobb-Douglas Production Function, calculate R-Squared for this model and
* conduct Durbin-Watson Autocorrelation Test
*
* Author(s):
* Skif Pankov
*
* Source:
* Damodar N. Gujarati and Dawn C. Porter, Basic Econometrics - 5th Edition
* McGraw-Hill International Edition, Chapter 14, Example 14.2 (page 532)
*
sample 1 20
* Reading the datafile and naming variables
read (data_14.2.shd) y x2 x3
* Initiating nonlinear regression procedure, stating that 1 equation with
* 3 coefficients should be estimated and storing the estimated derivatives,
* coefficients, residuals and predicted values
nl 1 / ncoef = 3 zmatrix = z coef = beta predict = yhat resid = reds
* Writing up an equation we would like to estimate - coefficients are named
* A, B and C
eq y = A*(x2**B)*(x3**C)
* Stating the initial values of coefficients - these shall be used as the starting
* points in the process of iterative estimation
coef A 0.5 B 0.5 C 0.5
end
* Generating R^2
gen1 su2 = sum(reds**2)
gen1 sy = sum((y-sum(y)/$N)**2)
gen1 r2 = 1 - (su2/sy)
print r2
* Generating a linear pseudomodel and computing the Durbin-Watson p-value
matrix ybar = y - yhat + z*beta
ols ybar z / noconstant dwpvalue
stop