0

I have the following Dataframe:

        Price            Quantity  Cost
1       6.979             800.359 1.830
2       7.420             427.363 1.830
3       7.408             486.639 1.830
4       7.613             574.584 1.830
5       8.059             621.247 1.830
6       8.445             498.810 1.830
7       7.864             635.192 1.830
8       9.629             405.185 1.830
9      12.137             364.420 1.830
10     10.945             241.486 1.830

enter image description here

I ran this:

ols=sm.OLS(annual['Price'],annual[['Price', 'Quantity']]).fit()
print(ols.predict([1,10]))

(I read here: What is first value that is passed into StatsModels predict function? that I need to add the 1 as constant)

My expected result would be ~340, actual result: [1.]

I also read that I should include the costs and use the IV2SLS regression like this:

IV = IV2SLS(annual['Price'],
                  annual[['Price', 'Quantity']],
                  annual[['Price', 'Cost']])

How do I get the prediction here?

I tried:

IV.fit().predict([1.83,10])

Again expected result ~340 Actual result: [1.83]

Thank you!

Joan Arau
  • 151
  • 4
  • 14
  • What are you trying to predict? I'm assuming `Quantity`? do you want both price and cost to be features in the model? – Chris Sep 14 '22 at 18:26
  • Yes I am trying to use the price of 10 to predict a quantity of ~340. Yes I read here: https://economics.stackexchange.com/questions/52459/real-world-price-elasticity-when-making-pricing-decisions that I should factor in the cost using the IV2SLS – Joan Arau Sep 14 '22 at 18:28

1 Answers1

0

I believe I have the inputs wrong. It works like this:

resultIV = IV2SLS(annual['menge_fig_adjusted'],
                  annual['Preis_fig'],
                  annual['Cost']).fit()



print(resultIV.predict([10,1.83]).mean())

Result 345

Joan Arau
  • 151
  • 4
  • 14