<p>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.</p>

CC BY-SA 3.0
2017-11-30T11:46:47.720Z
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
CC BY-SA 3.0
2017-11-30T12:42:00.917Z
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
CC BY-SA 3.0
2017-12-01T09:58:04.140Z
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
CC BY-SA 3.0
2017-12-01T10:22:39.417Z
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
CC BY-SA 3.0
2017-12-01T14:52:34.480Z
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
CC BY-SA 3.0
2017-12-01T14:56:50.193Z
but then I received the error: 

Fehler in numericDeriv(form[[3L]], names(ind), env) : 
Fehlender Wert oder etwas Unendliches durch das Modell erzeugt. Translated it means that there is an error in numericDeriv(form[[3L]], names(ind), env). Either theres a missing value or the model produces something infinite. Weird... since there are no missing values so something must have went wrong right?
macro123
CC BY-SA 3.0
2017-12-01T22:42:25.283Z
Again these are questions for either stack overflow or cross validated. Try googling the error or search for it in SO or CV. If you can post the data or make a reproducible example you can also post the question there. They are better able to help you with technical problems than I would.
Maarten Punt
CC BY-SA 3.0
2017-12-02T23:13:58.743Z
Okey I will post it on overflow too then. I tried googling it of course but I couldn't find anything that helped me in speficially. I mean I have the excel data set, but I dont think I'm able to attach it to a comment here as far as I looked up on this site.
macro123
CC BY-SA 3.0
2017-11-22T13:47:06.157Z
2017-11-22T13:47:06.157Z
Maarten Punt
<p>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. </p>

<pre><code>R&gt; set.seed( 123 ) 
R&gt; cesData &lt;- data.frame(x1 = rchisq(200, 10), x2 = rchisq(200, 10), x3 = rchisq(200, 10), x4 = rchisq(200, 10) ) 
R&gt; cesData$y2 &lt;- cesCalc( xNames = c( "x1", "x2" ), data = cesData, + coef = c( gamma = 1, delta = 0.6, rho = 0.5, nu = 1.1 ) ) 
R&gt; cesData$y2 &lt;- cesData$y2 + 2.5 * rnorm( 200 )
R&gt; cesData$y3 &lt;- 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&gt; cesData$y3 &lt;- cesData$y3 + 1.5 * rnorm(200) 
R&gt; cesData$y4 &lt;- 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&gt; cesData$y4 &lt;- cesData$y4 + 1.5 * rnorm(200)
</code></pre>

<p>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.</p>

<p>The authors did f.e. a non linear estimation the following way</p>

<pre><code>R&gt; cesNls &lt;- 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&gt; print( cesNls )
</code></pre>

<p>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</p>

<pre><code>R&gt; ceslan &lt;- 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 ) )
</code></pre>

<p>So i replicated</p>

<pre><code>R&gt; cesData$y2 &lt;- cesCalc( xNames = c( "x1", "x2" ), data = cesData, coef = c( gamma = 1, delta = 0.6, rho = 0.5, nu = 1.1 ) )
</code></pre>

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

<p>Afterwards I tried to do the non linear estimation</p>

<pre><code>R&gt; cesulan &lt;- 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) )
</code></pre>

<p>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?</p>

<elasticity><elasticity-of-substitution><ces-function>
CES production function application problem
macro123
# CES production function application problem

(Asked by: username_0 on 2017-11-21)

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?

**Tags:** elasticity, elasticity-of-substitution, ces-function

---

## 1 answers

### Answer by username_1 on 2017-11-22. Score: 1

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.

> **Comments:**
> **username_0**: 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?  
> **username_1**: 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.  
> **username_0**: 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?  
> **username_1**: 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  
> **username_0**: 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) )`  
> **username_0**: but then I received the error:   Fehler in numericDeriv(form[[3L]], names(ind), env) :  Fehlender Wert oder etwas Unendliches durch das Modell erzeugt. Translated it means that there is an error in numericDeriv(form[[3L]], names(ind), env). Either theres a missing value or the model produces something infinite. Weird... since there are no missing values so something must have went wrong right?  
> **username_1**: Again these are questions for either stack overflow or cross validated. Try googling the error or search for it in SO or CV. If you can post the data or make a reproducible example you can also post the question there. They are better able to help you with technical problems than I would.  
> **username_0**: Okey I will post it on overflow too then. I tried googling it of course but I couldn't find anything that helped me in speficially. I mean I have the excel data set, but I dont think I'm able to attach it to a comment here as far as I looked up on this site.  

---

