
R version 4.2.2 Patched (2022-11-10 r83330) -- "Innocent and Trusting"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> ## This script reproduces some of the results of
> ## Sun, K., Henderson, D.J. and Kumbhakar, S.C. (2011),
> ## Biases in approximating log production.
> ## Journal of Applied Econometrics, forthcoming.
> ## doi: 10.1002/jae.1229
> ##
> ## This paper is in fact a replication study of
> ## Masanjala, W.H. and Papageorgiou, C. (2004), 
> ## The Solow model with CES technology: nonlinearities and parameter 
> ## heterogeneity. Journal of Applied Econometrics, 19: 171–201.
> ## doi: 10.1002/jae.722
> ##
> ## The data used in the two above-mentioned papers are actually from
> ## Durlauf, S.N. and Johnson, P.A. (1995),
> ## Multiple Regimes and Cross-Country Growth Behavior. 
> ## Journal of Applied Econometrics, 10: 365–384.
> 
> # load the "micEconCES" package
> library( "micEconCES" )
Loading required package: minpack.lm
Loading required package: DEoptim
Loading required package: parallel

DEoptim package
Differential Evolution algorithm in R
Authors: D. Ardia, K. Mullen, B. Peterson and J. Ulrich

Loading required package: car
Loading required package: carData

To cite package 'micEconCES' in publications use:
  Henningsen, Arne, Géraldine Henningsen, and Gergő Literáti (2021):
  Econometric Estimation of the 'Constant Elasticity of Substitution'
  Function in R: the micEconCES Package. In Hashimzade, N. and M.
  Thornton (editors), Handbook of Research Methods and Applications in
  Empirical Microeconomics. Edward Elgar, p. 596–640.
  https://doi.org/10.4337/9781788976480.00030 (open access:
  https://bit.ly/3I5U310).

If you have questions, suggestions, or comments regarding the 'micEconCES' package, please use the 'issue' tracker at the GitHub page of the package:
https://github.com/micEcon/micEconCES
> options( digits = 3 )
> 
> # load data (included in the "AER" package)
> data( "GrowthDJ", package = "AER" )
> 
> # remove data from oil producing countries
> # as this has been done by Masanjala and Papageorgiou (2004)
> # and hence, also by Sun, Henderson, and Kumbhakar (2011)
> GrowthDJ <- subset( GrowthDJ, oil == "no" )
> 
> # calculate "input" variables for the Solow growth model
> GrowthDJ$x1 <- 1
> GrowthDJ$x2 <- ( GrowthDJ$popgrowth + 5 ) / GrowthDJ$invest
> 
> # CES: non-linear least-squares estimation (NLLS)
> cesNls <- cesEst( "gdp85", c( "x1", "x2"), data = GrowthDJ )
> summary(cesNls)
Estimated CES function with constant returns to scale

Call:
cesEst(yName = "gdp85", xNames = c("x1", "x2"), data = GrowthDJ)

Estimation by non-linear least-squares using the 'LM' optimizer
assuming an additive error term
Convergence achieved after 23 iterations
Message: Relative error in the sum of squares is at most `ftol'. 

Coefficients:
      Estimate Std. Error t value Pr(>|t|)  
gamma  646.141    549.993    1.17    0.240  
delta    3.977      2.239    1.78    0.076 .
rho     -0.197      0.166   -1.19    0.235  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3314 
Multiple R-squared: 0.602 

Elasticity of Substitution:
            Estimate Std. Error t value Pr(>|t|)    
E_1_2 (all)    1.245      0.257    4.84  1.3e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

> cesNlsCoef <- coef( cesNls )
> delta <- cesNlsCoef[ "delta" ]
> rho <- cesNlsCoef[ "rho" ]
> print( alpha <- ( delta - 1 ) / delta )
delta 
0.749 
> print( sigma <- 1 / ( 1 - rho ) )
  rho 
0.835 
> cesNlsVar <- vcov(cesNls)
> # deltamethod(~-x2/(1-x2), cesNlsCoef, cesNlsVar)
> # deltamethod(~1/(1-x3), cesNlsCoef, cesNlsVar)
> 
> # Cobb-Douglas: non-linear least-squares estimation (NLLS)
> cdNls <- cesEst( "gdp85", c( "x1", "x2"), data = GrowthDJ, rho = 0 )
> summary(cdNls)
Estimated CES function with constant returns to scale

Call:
cesEst(yName = "gdp85", xNames = c("x1", "x2"), data = GrowthDJ, 
    rho = 0)

Estimation by non-linear least-squares using the 'LM' optimizer
assuming an additive error term
Coefficient 'rho' was fixed at 0 
Convergence achieved after 7 iterations
Message: Relative error in the sum of squares is at most `ftol'. 

Coefficients:
      Estimate Std. Error t value Pr(>|t|)    
gamma 1288.080    543.177    2.37  0.01772 *  
delta    2.443      0.695    3.51  0.00044 ***
rho      0.000      0.161    0.00  1.00000    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3342 
Multiple R-squared: 0.595 

Elasticity of Substitution:
            Estimate Std. Error t value Pr(>|t|)    
E_1_2 (all)    1.000      0.161    6.22  5.1e-10 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

> cdNlsCoef <- coef( cdNls )
> delta <- cdNlsCoef[ "delta" ]
> print( alpha <- ( delta - 1 ) / delta )
delta 
0.591 
> 
> # Cobb-Douglas: estimation with logs
> cdLog <- cesEst( "gdp85", c( "x1", "x2"), data = GrowthDJ, rho = 0, multErr = TRUE )
Warning message:
In log(gammaStar) : NaNs produced
> summary(cdLog)
Estimated CES function with constant returns to scale

Call:
cesEst(yName = "gdp85", xNames = c("x1", "x2"), data = GrowthDJ, 
    multErr = TRUE, rho = 0)

Estimation by non-linear least-squares using the 'LM' optimizer
assuming a multiplicative error term
Coefficient 'rho' was fixed at 0 
Convergence achieved after 8 iterations
Message: Relative error in the sum of squares is at most `ftol'. 

Coefficients:
      Estimate Std. Error t value Pr(>|t|)    
gamma  965.234    120.400    8.02  1.1e-15 ***
delta    2.488      0.304    8.19  2.5e-16 ***
rho      0.000      0.106    0.00        1    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.681 
Multiple R-squared: 0.597 

Elasticity of Substitution:
            Estimate Std. Error t value Pr(>|t|)    
E_1_2 (all)    1.000      0.106    9.47   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

> cdLogCoef <- coef( cdLog )
> delta <- cdLogCoef[ "delta" ]
> print( alpha <- ( delta - 1 ) / delta )
delta 
0.598 
> 
> 
> proc.time()
   user  system elapsed 
  1.137   0.085   1.214 
