# CES production function application problem

I'm currently trying to do some estimations using the micEconCES package in R by Henningsen/Henningsen (2011). My issue is that I am not very familiar with R and I'm trying to implement my own dataset to get the estimations with the package. They authors of the paper created this data set for the estimations.

R> set.seed( 123 )
R> cesData <- data.frame(x1 = rchisq(200, 10), x2 = rchisq(200, 10), x3 = rchisq(200, 10), x4 = rchisq(200, 10) )
R> cesData$y2 <- cesCalc( xNames = c( "x1", "x2" ), data = cesData, + coef = c( gamma = 1, delta = 0.6, rho = 0.5, nu = 1.1 ) ) R> cesData$y2 <- cesData$y2 + 2.5 * rnorm( 200 ) R> cesData$y3 <- cesCalc(xNames = c("x1", "x2", "x3"), data = cesData, coef = c( gamma = 1, delta_1 = 0.7, delta = 0.6, rho_1 = 0.3, rho = 0.5, + nu = 1.1), nested = TRUE )
R> cesData$y3 <- cesData$y3 + 1.5 * rnorm(200)
R> cesData$y4 <- cesCalc(xNames = c("x1", "x2", "x3", "x4"), data = cesData, coef = c(gamma = 1, delta_1 = 0.7, delta_2 = 0.6, delta = 0.5, rho_1 = 0.3, rho_2 = 0.4, rho = 0.5, nu = 1.1), nested = TRUE ) R> cesData$y4 <- cesData$y4 + 1.5 * rnorm(200)  The ﬁrst line sets the“seed”for the random number generator so that these examples can be replicated with exactly the same data set. The second line creates a data set with four input variables (called x1, x2, x3, and x4) that each have 200 observations and are generated from random χ2 distributions with 10 degrees of freedom. The third, ﬁfth, and seventh commands use the function cesCalc, which is included in the micEconCES package, to calculate the deterministic output variables for the CES functions with two, three, and four inputs (called y2, y3, and y4, respectively) given a CES production function. Now in my paper I'm trying to estimate the CES function for the U.S. at the Aggregate Level for the two input case with capital and labor. So what I did is I gathered data from the World Bank Data Base from 1990-2015, where I used Gross Fixed Capital Formation for capital and total Labor Force for Labor. The authors did f.e. a non linear estimation the following way R> cesNls <- nls( y2 ~ gamma * ( delta * x1^(-rho) + (1 - delta) * x2^(-rho) )^(-phi / rho), + data = cesData, start = c( gamma = 0.5, delta = 0.5, rho = 0.25, phi = 1 ) ) R> print( cesNls )  Now I want the exact same thing for my own data Set which is called Data_Extract_From_World_Development_Indicators. So what I did is firstly R> ceslan <- cesCalc( xNames = c( "GrossFixedCapitalFormation", "LaborForce" ), data = Data_Extract_From_World_Development_Indicators, coef = c( gamma = 1, delta = 0.6, rho = 0.5, nu = 1.1 ) )  So i replicated R> cesData$y2 <- cesCalc( xNames = c( "x1", "x2" ), data = cesData, coef = c( gamma = 1, delta = 0.6, rho = 0.5, nu = 1.1 ) )


All I did was changing the name of the Dataset and replaced x1 and x2 with my two variables for capital and Labor.

Afterwards I tried to do the non linear estimation

R> cesulan <- nls(y2 ~ gamma * (delta * GrossFixedCapitalFormation^(-rho) + (1-delta)*LaborForce^(-rho))^(-phi / rho), data = Data_Extract_From_World_Development_Indicators, start = c(gamma = 0.5, delta = 0.5, rho = 0.25, phi = 1) )


Now this is where my Problem is: I dont know what variable is meant to be y2 in my dataset. I can see in the formula that y2 ~ gamma *... so ist plotted against the rest of the term, but I dont know what Kind of value I need to plug in there. Does anyone have any advice?

## 1 Answer

Your y2 needs to be the output associated produced with those inputs. Given that you have a CES production function and you use World Bank Country data as inputs, you need output of the countries in that specific year. Typically we use GDP as a measure of output at country level. You can get it a.o. from the World Bank.

• So I added the column GDP but when I replaced y2 with GDP in the formula above: cesulan <- nls(GDP ~ gamma * (delta * GrossCapitalFormation^(-rho) + (1-delta)*LaborForce^(-rho))^(-phi / rho), data = Popular_Indicators_2_, start = c(gamma = 0.5, delta = 0.5, rho = 0.25, phi = 1) ) I get the error non non-numeric argument for a binary operator. Whats wrong now? – macro123 Nov 30 '17 at 11:46
• That's more a question for stack overflow than for economics. In any case the error is typically caused if you try to carry out a non-sensical operation like adding a number to a character. Although there are potentially many things that cause it, my first check would be if the imported data is actually numeric. – Maarten Punt Nov 30 '17 at 12:42
• Hmm yeah, but its weird because all the data for Labor Force, Gross Capital Formation and GDP I got from the World Bank are obviously numerics right? – macro123 Dec 1 '17 at 9:58
• Sure but it never hurts to check. Especially if the world bank data contains a symbol for NA that R doesn't recognize as such. In that case it thinks it's a character and will convert all data in that column to characters – Maarten Punt Dec 1 '17 at 10:22
• You were right the numbers were defined somehow as characters, so I switched it to numerics with Popular_Indicators_2_ <- read_excel("~/Downloads/Popular Indicators (2).xlsx", + col_types = c("numeric", "text", "text", + "text", "numeric", "numeric", "numeric", + "numeric")) so again I ran the code cesulan <- nls(GDP ~ gamma * (delta * GrossCapitalFormation^(-rho) + (1-delta)*LaborForce^(-rho))^(-phi / rho), data = Popular_Indicators_2_, start = c(gamma = 0.5, delta = 0.5, rho = 0.25, phi = 1) ) – macro123 Dec 1 '17 at 14:52