<jupyter_start><jupyter_text>We are interested, among other things, in the price elacticity of gasoline consumption. Variable Defintions:|**Variable**| **Defintion**                             | **Units**    ||------------|:--------------------------------------------:|--------------:|| SGAS       | Retail Sales Gasoline                      | 10^6 dolars  || PGAS       | Gasoline Retail Price                      | Cents/Gallon || INC        | Nominal Disposable Income                  | 10^9 dollars || PALL       | $\dfrac{1982 + 1983 +1984}{3} = 100$       |              || PPUB       | CPI of Public Transportation               |              || PNCAR      | CPI of New Cars                            |              || PUCAR      | CPI of Used Cars                           |              |* $y = log \left (\dfrac{SGAS}{PGAS} \right )$* $x_{2} = log \left (\dfrac{INC}{PALL} \right )$* $x_{3} = log \left (\dfrac{PGAS}{PALL} \right )$* $x_{4} = log \left (\dfrac{PPUB}{PALL} \right )$* $x_{5} = log \left (\dfrac{PNCAR}{PALL} \right )$* $x_{6} = log \left (\dfrac{PUCAR}{PALL} \right )$ Question 1: Regress lg(SGAS) on lg(PGAS).<jupyter_code>y = np.log(df['SGAS'])
x = np.log(df[['PGAS']])
clf = LinearRegression()
clf.fit(x.values,y.values)
print('Logarithm of Gasoline Retail Price')
print(clf.coef_)
print()
print('Intercept:')
print(clf.intercept_)<jupyter_output>Logarithm of Gasoline Retail Price
[1.19513055]

Intercept:
6.046774170755111<jupyter_text>Is that what we are intersted in?|**Variable**| **Defintion**                             | **Units**    ||------------|:--------------------------------------------:|--------------:|| SGAS       | Retail Sales Gasoline                      | 10^6 dolars  || PGAS       | Gasoline Retail Price                      | Cents/Gallon |$ \widehat{log \left (SGAS\right )} = \hat\beta_{0} + \hat\beta_{1} log\left(PGAS\right)$As we are interested in the price elasticity of gasoline consumption, this tells us the percent change in retail sales of gasoline (in 10^6 dollars) given a percent change in gasoline retail price (in cents per gallon). The interpretation of a log-log model is a percent change in y given a percent change in x (times the coefficient).Price elasticity of demand involves the change in quantity demanded and the price of the good demanded.**No**, there is no aspect of quantity in this model  Question 2: Regress y on lg(PGAS).<jupyter_code>y = np.log(df['SGAS'] / df['PGAS'])
x = np.log(df[['PGAS']])
clf = LinearRegression()
clf.fit(x.values,y.values)
print('Logarithm of Gasoline Retail Price')
print(clf.coef_)
print()
print('Intercept:')
print(clf.intercept_)<jupyter_output>Logarithm of Gasoline Retail Price
[0.19513055]

Intercept:
6.046774170755112<jupyter_text>Why is this misleading?|**Variable**| **Defintion**                             | **Units**    ||------------|:--------------------------------------------:|--------------:|| SGAS       | Retail Sales Gasoline                      | 10^6 dolars  || PGAS       | Gasoline Retail Price                      | Cents/Gallon |$ \widehat{log \left (\dfrac{SGAS}{PGAS} \right )} = \hat\beta_{0} + \hat\beta_{1} log\left(PGAS\right) = 6.0468 + 0.1951*log\left(PGAS\right) $This is a log-log interpretation again, with Y being defined as the log of the ratio of retail sales of gasoline in 10^6 dollars to the gasoline retail price.This is misleading as the units are not standard and the terms are in nominal and realStatistically, this is misleading as the Y variable is composed of some of the X variable, and thus there is certainly an endogeneity issue. Mathematically, this is odd as we aren't really "solving" for anything, and if we are, we're solving it in terms of itself.**More particularly, there is an issue of relating nominal and real values.**  Question 3: Regress y on x2 and x3.<jupyter_code>y = np.log(df['SGAS'] / df['PGAS'])
x = df[['X2', 'X3']]
clf = LinearRegression()
clf.fit(x.values,y.values)
print('log(INC/PALL), log(PGAS/PALL)')
print(clf.coef_)
print()
print('Intercept:')
print(clf.intercept_)<jupyter_output>log(INC/PALL), log(PGAS/PALL)
[ 0.57322022 -0.52757783]

Intercept:
4.9859972129091865<jupyter_text>Provide some motivation for this choice.|**Variable**| **Defintion**                             | **Units**    ||------------|:--------------------------------------------:|--------------:|| SGAS       | Retail Sales Gasoline                      | 10^6 dolars  || PGAS       | Gasoline Retail Price                      | Cents/Gallon || INC        | Nominal Disposable Income                  | 10^9 dollars || PALL       | $\dfrac{1982 + 1983 +1984}{3} = 100$       |              |$ \widehat{log \left (\dfrac{SGAS}{PGAS} \right )} = \hat\beta_{0} + \hat\beta_{1} log \left (\dfrac{INC}{PALL} \right ) + \hat\beta_{2} log \left (\dfrac{PGAS}{PALL} \right ) = 4.9860 + 0.5732 * log \left (\dfrac{INC}{PALL} \right ) + -0.5276 * log \left (\dfrac{PGAS}{PALL} \right )$The choices of real-income and real-gas price may be a good choice for estimating the elasticity of quantity demanded as economic theory tells us that only real opportunities matter (i.e. relative prices to relative goods, homogeneity of degree zero and all that) and that demand is a function of prices and wealth.The results seem reasonable: as wealth increases, demand increases (shifting quantity demanded, which is what's being observed), as price increases, quantity demanded decreases.  Question 4: Regress y on X2, X3, X4, X5, and X6.<jupyter_code>y = np.log(df['SGAS'] / df['PGAS'])
x = df[['X2', 'X3', 'X4', 'X5', 'X6']]
clf = LinearRegression()
clf.fit(x.values,y.values)
print('X2 = log(INC/PALL), X3 = log(PGAS/PALL), X4 = log(PPUB/PALL), X5 = log(PNCAR/PALL), X6 = log(PUCAR/PALL)')
print(clf.coef_)
print()
print('Intercept:')
print(clf.intercept_)<jupyter_output>X2 = log(INC/PALL), X3 = log(PGAS/PALL), X4 = log(PPUB/PALL), X5 = log(PNCAR/PALL), X6 = log(PUCAR/PALL)
[ 0.86605094 -0.43960435  0.03351302  0.39028831 -0.09466594]

Intercept:
3.992342363706894<jupyter_text>Compare your result to 3.|**Variable**| **Defintion**                             | **Units**    ||------------|:--------------------------------------------|--------------:|| SGAS       | Retail Sales Gasoline                      | 10^6 dolars  || PGAS       | Gasoline Retail Price                      | Cents/Gallon || INC        | Nominal Disposable Income                  | 10^9 dollars || PALL       | $\dfrac{1982 + 1983 +1984}{3} = 100$       |              || PPUB       | CPI of Public Transportation               |              || PNCAR      | CPI of New Cars                            |              || PUCAR      | CPI of Used Cars                           |              | Regression 4:$ \widehat{log \left (\dfrac{SGAS}{PGAS} \right )} = 3.9923 + 0.8661 * log \left (\dfrac{INC}{PALL} \right ) + -0.4396 * log \left (\dfrac{PGAS}{PALL} \right ) + 0.0335 * log \left (\dfrac{PPUB}{PALL} \right ) + 0.3903 * log \left (\dfrac{PNCAR}{PALL} \right ) + -0.0947 * log \left (\dfrac{PUCAR}{PALL} \right )$ Regression 3:$ \widehat{log \left (\dfrac{SGAS}{PGAS} \right )} = 4.9860 + 0.5732 * log \left (\dfrac{INC}{PALL} \right ) + -0.5276 * log \left (\dfrac{PGAS}{PALL} \right )$I'm unsure about relating the CPI of 1982 through 1984 to the CPI of New and Used Cars and Public Transportation, but with including substitutes goods (new cars are substitutes for used cars are substitutes for public transportation), the effect of a change in wealth has more influence in the new model (Regression 4) and the effect of a change in the price of gas has less influence in the new model.|**Regression 3**| **Relation**                             | **Regression 4**    ||------------|:--------------------------------------------:|--------------|| $log \left (\dfrac{INC}{PALL} \right )$ | <                      | $log \left (\dfrac{INC}{PALL} \right )$  || $log \left (\dfrac{PGAS}{PALL} \right )$| >                    | $log \left (\dfrac{PGAS}{PALL} \right )$ |  3-D Plotting<jupyter_code>fig = plt.figure(dpi= 200)
ax = fig.gca(projection='3d')
z = np.log(df['SGAS'] / df['PGAS'])
x = df['X2']
y = df['X3']
ax.scatter(x, y, z, zdir='z', label='X2 & X3')
ax.legend()
fig.savefig('fig.png',dpi=600)

plt.title('3D Plot of X2 & X3 on Y', loc='center',)

plt.show()<jupyter_output><empty_output><jupyter_text>INTERACTIVE 3D PLOT !!!WARNING!!!  UNLESS YOU HAVE A PLOTLY ACCOUNT AND HAVE SET YOUR SYSTEM TO EMPLOY YOUR CREDENTIALS, DO NOT RUN THIS CODE, IT WILL BREAK  !!!WARNING!!!<jupyter_code>import plotly.plotly as py
import plotly.graph_objs as go

z = np.log(df['SGAS'] / df['PGAS'])
x = df['X2']
y = df['X3']

data = [
    go.Scatter3d(x = x, y = y, z = z,mode='markers',
    marker=dict(
        size=12,
        line=dict(
            color='rgba(217, 217, 217, 0.14)',
            width=0.5
        ),
        opacity=0.8
    )
)

]
go.Scatter3d()

py.iplot(data,filename='multiple-surfaces')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18550627987106813, 'fraction_numerical': 0.042903189952206294, 'mean_word_length': 2.3512104283054005, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '457174', 'license': 'Unlicense', 'n_tokens_mistral': 3196, 'n_tokens_neox': 2834, 'n_words': 855, 'path': 'Exercises/DaigleTakeHome30Oct2018.ipynb', 'repo_name': 'ChristopherDaigle/ConvexOptimizationWithPython', 'size': '8997'}