0

I am trying define a constant as a coefficient from an r regression. I.e. trying to define elasticity as the number -1.64431 that you can see in the photo.

enter image description here

reg <- lm(ln_q ~ ln_price, data=df) 
elasticity <- reg[["coefficients","ln_price"]]
print(elasticity)

I get the error:

Error in reg[["coefficients", "ln_price"]] : 
  incorrect number of subscripts

Any help much appreciated! :)

neilfws
  • 32,751
  • 5
  • 50
  • 63
jimmy.lit
  • 3
  • 1

1 Answers1

0
elasticity <- reg$coefficients[names(reg$coefficients)=="ln_price"]
Jordan Hackett
  • 689
  • 3
  • 11