2

How can I calculate factors elasticity in R? For example, "Calculate tenure elasticity of wage for all women in sample" from the dataset nlsw88

h <- read.dta("nlsw88.dta")
h1 <- mutate(h, age = log(h$age), wage = log(h$wage))
model2 <- lm(data = h1,
             wage ~ age + race + married + never_married + grade + collgrad + industry + union + occupation + hours + ttl_exp + tenure + c_city)

I use this formula to calculate elasticity

elas1<-as.numeric(model2$coefficients["age"]*mean(h1$age)/mean(h1$wage))
-0.2217391

But using this formula i can't calculate "race" elasticity, because it's not numerical, FUthermore, R write me NA_real_ if i put elas3<-as.numeric(model2$coefficients["hours"]*mean(h1$hours)/mean(h1$wage))

What's wrong?

Spacedman
  • 92,590
  • 12
  • 140
  • 224
Dmitrii
  • 41
  • 1
  • 2
  • 6
  • 1
    As said in [a comment to your previous question](http://stackoverflow.com/questions/43570405/error-variables-were-specified-with-different-types-from-the-fit-with-nlsw88-da), you need to include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). Furthermore, it is also helpful to show what you've tried already and why it didn't work (possibly including error-messages). – Jaap Apr 23 '17 at 15:01
  • I know how to calculate marginal effect of factor, it's a part of formula elasticity, but i dunno command, that find elasticity – Dmitrii Apr 23 '17 at 15:09

1 Answers1

3

It is difficult to give an accurate answer, when you do not include any reproducible example, but here is an example on how to calculate the elasticity of demand:

 # Create a data
 df = data.frame(sales = c(18,20,22,23), Price=c(4.77,4.67,4.75,4.74))

 # Run regression 
 formula = lm(sales~., data=df)

 # Get the summary of the regression 
 summary(formula)

 #Call:
 #lm(formula = sales ~ ., data = df)

 #Residuals:
 #      1       2       3       4 
 #-2.6344 -0.9427  1.3040  2.2731 

 #Coefficients:
 #            Estimate Std. Error t value Pr(>|t|)
 #(Intercept)   35.344    170.297   0.208    0.855
 #Price         -3.084     35.983  -0.086    0.940

To calculate Elasticity of Demand we use the formula: PE = (ΔQ/ΔP) * (P/Q)

(ΔQ/ΔP) is determined by the coefficient -3.084 in our regression formula.

To determine (P/Q) we will use the mean Price (4.73) and mean Sales (20.75).

  The PE = -3.084 * 4.73/20.75 = -0.70

  formula$coefficients["Price"]*mean(df[,2])/mean(df[,1])
  # -0.7033066 

This means that an increase in the price[of a given product in your case the wage] by 1 unit will decrease the sales by 0.70 units.

Hope it helps

Boro Dega
  • 393
  • 1
  • 3
  • 13
  • Thanks, but what we do with no numeric factors, that can be onely "1" or "0" – Dmitrii Apr 23 '17 at 18:33
  • It is a good question and I am not sure whether I am the right person to answer. The elasticity need to be calculated when the factor goes from 1 to 0 and vice versa. I am sure the calculation is possible using the factors beta, however I am not sure how you would interpret it. – Boro Dega Apr 24 '17 at 19:30
  • If it will "1", it is one value of elasticity, if it will "0" - another value, but if we have many different observations, how it use with a formula, may be with logical operators? – Dmitrii Apr 25 '17 at 16:03
  • you need a log ~ log model to estimate elasticity. – marbel Feb 20 '18 at 13:53