Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

--- title: "Final Instruction" author: "Utkarsh" date: "6/06/2021" output: pdf_document --- ```{r, results = "FALSE", echo=FALSE, message = FALSE, warning = FALSE} # Load relevant packages...

1 answer below »
---
title: "Final Instruction"
author: "Utkarsh"
date: "6/06/2021"
output: pdf_document
---
```{r, results = "FALSE", echo=FALSE, message = FALSE, warning = FALSE}
# Load relevant packages
li
ary(knitr)
li
ary(rmarkdown)
knitr::opts_chunk$set(results = "asis")
li
ary(dplyr)
li
ary(data.table)
li
ary(stargazer)
li
ary(tidyverse)
li
ary(clusterSEs)
li
ary(AER)
li
ary(plm)
li
ary(dummies)
li
ary(gmm)
li
ary(boot)
li
ary(kableExtra)
li
ary(readxl)
li
ary(
mle)
```
## R Markdown - Use the help option for markdown features
Write your text here.
1. Can choose to not use markdown but make sure your code is well commented as I demonstrate below
-- I will share this file with all of you
-- Will also upload a sample code and a rendered pdf so that you can see how to write math equations in markdown
2. This includes pointers on what your thought process was while writing code
3. I should be easily able to run your code file and look at output.
```{r, results = "FALSE", echo=FALSE, message = FALSE, warning = FALSE}
### Question 1 Solution
# Part A - Import data and preliminaries
m(list = ls())
setwd("~/Dropbox/3rd yea
Summer_TA/Problem sets/")
getwd()
setwd("Problem sets")
getwd()
data <- read.table("Problem sets/data.txt", quote="\"", comment.char="")
# Demonstrate using stackoverflow
colnames(data) <- c("price", "quantity","weight", "hp","AC", "firm")
# Sorting data by price
data <- data[order(data$price), ]
# Part B - Creating shares for each car
#data$number <- n
P = XXXXXXXXXX
J = 131
lambda <- 4*(10^(-6))
data$share <- (data$quantity)/P
s_0 <- 1-sum(data$share)
# Part C -
data$cumsum_shares <- s_0 + cumsum(data$share)
# Let's back out deltas
data$delta <- 0
data$delta[1] <- ((data$price[1])*(log(s_0)))/(-lambda)
# Calculate deltas from delta2 - delta130 because delta131 is going to be different
# Write a for loop here
for (i in 2:J){
data$delta[i]=data$delta[i-1] + ((data$price[i]-data$price[i-1])*(log(data$cumsum_shares[i-1])))/(-lambda)
}
# Delta131
## Run your OLS. Q1 done! delta ~ x.......and interpret what you get
## Problem 2 is derivatives and elasticities
# 2 dimensional for loop for matrices
# 1st step: create J times J matrix of zeros D
D <- matrix(0, nrow = J, ncol = J)
for (i in 1:J){
for (j in 1:J){
# Figure out the indices for zeros
if (i==j) {
D[i,j] = 1 ## Write the co
ect formula with co
ect indices
} else if (j == i+1) {
D[i,j] = -1
} else if (j == i-1) {
D[i,j] = -2
} else {
D[i,j] = 0
}
}
}
# Elasticity E[i,j]=(data$price[i])*D(i,j)
## Same for elasticity
E <- matrix(0, nrow = J, ncol = J)
for (i in 1:J){
for (j in 1:J){
# Figure out the indices for zeros
if (i==j) {
E[i,j] = D[i,j]*(data$price[i]/data$quantity[i])
} else if (j == i+1) {
E[i,j] = -1
} else if (j == i-1) {
E[i,j] = -2
} else {
E[i,j] = 0
}
}
}
data$mcpricing <- data$price
data$lag_hp <- 0
for (i in 2:J) {
data$lag_hp[i]=data$hp[i-1]
}
```

ECON S4251 Final Empirical Exercise∗
Due: SEE COURSEWORKS
You can work in groups but please turn in your own answers and code (please do not bo
ow
code except for small bits. The key to writing code is incessant googling and stackoverflow). Please
make sure your code is very well commented and clearly explains what your understanding was while
writing the code. If you are using R, try working with RMarkdown which lets you write code and text
simultaneously (see the sample file I uploaded). It’ll be a steep learning curve but will certainly have
high returns.
We will use data on a cross-section of 1990 automobile prices, quantities and characteristics. You
can download the data from the Canvas web page. The data set is tab delimited with the following
columns: price (in dollars), quantity sold, car weight, horse power, AC, and firm dummy. You should
assume throughout that the market size M is equal to 10 million. Consider a model similar to Bres-
nahan’s vertical model of the auto industry. Each consumer i has utility for product j as a function
of price and product quality, j of:
uij = δj − αipj
The distribution of consumer price sensitivity, αi, is exponential with parameter λ. Assume that
δ = xj β + ξj and that marginal cost is given by mcj = xj γ + ηqj + ωj . Assume that ξ and ω are
unco
elated with all the characteristics of all the products (except price and quantity of course, for
which you will need to instrument appropriately, where necessary).
1. For simplicity, assume λ = 4 × 10−6. Estimate the remaining parameters (β4×1, γ4×1, η1×1) of
the model from just demand data. Provide all the necessary details.
(a) Step 1: Import data and sort the data with respect to prices. The idea is that in the world
of vertical differentiation (Bresnahan 1987) a product can have a higher price only if it is
etter quality.
(b) Add a column to the data with shares of each of 131 cars calculated as ratio of quantity sold
to M (total population). Also calculate the share of people who did not buy a car (share of
people choosing the outside option of no car).
(c) Backing out δ′js (product qualities). We do these using the utility function uij = δj −αipj .
Assume utility from the outside option to be ui0 = 0. Then,
i. Calculating δ1. The share of people going for the outside option, say s0 (calculated
in part (b)) determines δ1 by inverting the cdf of αi (F (x) = 1− e−λx) in the following
way: First write down the condition for people who choose the outside option, i.e.
ui1 < 0
=⇒ δ1 − αip1 < 0
=⇒ αi
δ1
p1
∗Adopted from Matt Backus' PhD Class
1
This gives us
s0 = Pr(αi
δ1
p1
)
= 1− F ( δ1
p1
)
= e−λ
δ1
p1
=⇒ δ1 =
p1log(s0)
−λ
ii. Calculate δ′s for all but the last good. For all but the highest priced car, you
may use the conditions of following style (I illustrate how to calculate δ2): We use the
demand for lowest priced cars. The demand is given by
ui1 > 0 =⇒ αi
δ1
p1
ui1 > ui2 =⇒ αi
δ2 − δ1
p2 − p1
=⇒ s1 = Pr(
δ2 − δ1
p2 − p1
αi
δ1
p1
)
More generally, for cars ranked 2 to 130 (there are 131 cars),
sj = Pr(
δj+1 − δj
pj+1 − pj
αi
δj − δj−1
pj − pj−1
)
The code for this part will look like a ’for loop’ which uses the preceding δ value to
calculate the next.
iii. Calculate δ for the last good. We need
ui131 > ui130
δ131 − αip131 > δ130 − αip130
=⇒ αi
δ131 − δ130
p131 − p130
So, we get
s131 = Pr(αi
δ131 − δ130
p131 − p130
)
s131 = 1− e−λ(
δ131−δ130
p131−p130
)
Invert this to get δ131.
(d) So now you have an additional column in your dataset that co
esponds to δ′s. Great!
(e) Lets calculate the parameters.
i. β is simple. Run an OLS regression of δ on x where x is a 131×4 matrix of variables ca
weight, horse power, AC, and firm dummy. How would you interpret the coefficients
on each of the independent variables (x′s).
ii. Great! Next, we shall use IV regression to calculate γ and η. But notice we we do not
have data on the variable mc (marginal cost) in the regression
mcj = xjγ + ηqj + ωj
We get back to this in part 3. But for now, let’s first calculate some elasticities in part
2.
2
2. Calculate own and cross price elasticities for each car. This will be a 131 × 131 matrix (!)
(so please use automation - a ’for loop’). Use the estimates to show why own and cross price
elasticities from this vertical model can be unrealistic (For starters, we would expect own price
elasticities to be negative. What else? - Too many zeros?)
(a) Use the demand function to calculate elasticities
Lowest quality : q1 = e
−λ δ2−δ1p2−p1 − e−λ
δ1
p1
Intermediate quality : qi = e
−λ δi+1−δipi+1−pi − e−λ
δi−δi−1
pi−pi−1
Highest Quality : qH = 1− e−λ
δ131−δ130
p131−p130
Do the calculations in two steps:
i. Calculate a matrix of cross derivatives (131 × 131). Below is an example of a 5 good
case:
d5×5 =

∂q1
∂p1
∂q1
∂p2
∂q1
∂p3
∂q1
∂p4
∂q1
∂p5
∂q2
∂p1
∂q2
∂p2
∂q2
∂p3
∂q2
∂p4
∂q2
∂p5
∂q3
∂p1
∂q3
∂p2
∂q3
∂p3
∂q3
∂p4
∂q3
∂p5
∂q4
∂p1
∂q4
∂p2
∂q4
∂p3
∂q4
∂p4
∂q4
∂p5
∂q5
∂p1
∂q5
∂p2
∂q5
∂p3
∂q5
∂p4
∂q5
∂p5

ii. Now, multiple each component in this matrix with the appropriate ratio of prices to
quantities. The matrix would look like
E5×5 =

∂q1
∂p1
p1
q1
∂q1
∂p2
p2
q1
∂q1
∂p3
p3
q1
∂q1
∂p4
p4
q1
∂q1
∂p5
p5
q1
∂q2
∂p1
p1
q2
∂q2
∂p2
p2
q2
∂q2
∂p3
p3
q2
∂q2
∂p4
p4
q2
∂q2
∂p5
p5
q2
∂q3
∂p1
p1
q3
∂q3
∂p2
p2
q3
∂q3
∂p3
p3
q3
∂q3
∂p4
p4
q3
∂q3
∂p5
p5
q3
∂q4
∂p1
p1
q4
∂q4
∂p2
p2
q4
∂q4
∂p3
p3
q4
∂q4
∂p4
p4
q4
∂q4
∂p5
p5
q4
∂q5
∂p1
p1
q5
∂q5
∂p2
p2
q5
∂q5
∂p3
p3
q5
∂q5
∂p4
p4
q5
∂q5
∂p5
p5
q5

(HINT: Note that demand for each product is only affected by price of the neighboring
goods.)
3. Use both the demand system and the pricing equation to estimate the identified parameters of
the model under the four following assumptions: (i) marginal cost pricing, (ii) single product
firms setting prices in a Nash Equili
ium, (iii) multi-product firms setting prices in a Nash
Equili
ium, (iv) perfect collusion by the firms (joint profit maximization). Present the results
of your work and discuss them
iefly.
(a) Remember what we want to do. We want to estimate the remaining 5 parameters [γ4×1, η].
In order to estimate these parameters, we need to first calculate marginal costs and then
un IV regressions of the form
mcj = xjγ + ηqj + ωj
Each of the four assumptions in this part will give you a column for mc (marginal costs) in
the following way:
i. Marginal cost pricing is simple. mcj = pj
ii. For the remaining cases, you need to create an H matrix (3 matrices of dimensions
131× 131) and apply the following formula to calculate marginal costs
mc131×1 = price131×1 + (H ◦ d′)−1131×131 × shares131×1
3
I
Answered 1 days After Jun 22, 2021

Solution

Mohd answered on Jun 23 2021
148 Votes
-
-
-
6/22/2021
importing Data
fdata<-read.delim("data.txt")
colnames(fdata) <- c("price", "quantity","weight", "hp","AC", "firm")
Sorting data by price
fdata <- fdata[order(fdata$price), ]
Part B - Creating shares for each ca
#data$number <- n
P = 10000000
J = 130
lambda <- 4*(10^(-6))
fdata$share <- (fdata$quantity)/P
s_0 <- 1-sum(fdata$share)
Part C -
fdata$cumsum_shares <- s_0 + cumsum(fdata$share)
# Let's back out deltas
fdata$delta <- 0
fdata$delta[1] <- ((fdata$price[1])*(log(s_0)))/(-lambda)
# Calculate deltas from delta2 - delta130 because delta131 is going to be different
# Write a for loop here
for (i in 2:J){
fdata$delta[i]=fdata$delta[i-1] +((fdata$price[i]-fdata$price[i-1])*(log(fdata$cumsum_shares[i-1])))/(-lambda)
}
Delta131
fdatadelta[131]-fdataprice[131]-fdata$price[130]))
## Run your OLS. Q1 done! delta ~ x.......and interpret what you get
mod<-lm(delta~weight+hp+AC+firm,fdata)
stargazer(mod,type="text")
##
## ===============================================
## Dependent variable:
## ---------------------------
## delta
## -----------------------------------------------
## weight 657,375.100***
## (119,935.900)
##
## hp 3,551,763.000***
## (1,343,603.000)
##
## AC 137,140,723.000
## (117,822,084.000)
##
## firm -14,747,662.000***
## (5,260,257.000)
##
## Constant 2,448,790,181.000***
## (255,890,879.000)
##
## -----------------------------------------------
## Observations 130
## R2 0.681
## Adjusted R2 0.671
## Residual Std. E
or 394,975,856.000 (df = 125)
## F Statistic 66.677*** (df = 4; 125)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
coeftest(mod, vcov = vcovHC, type = "HC1")
##
## t test of coefficients:
##
## Estimate Std. E
or t value Pr(>|t|)
## (Intercept) 2448790181 344689866 7.1043 8.111e-11 ***
## weight 657375 136775 4.8062 4.329e-06 ***
## hp 3551763 1298427 2.7354 0.007136 **
## AC 137140723 111286470 1.2323 0.220142
## firm -14747662 6029049 -2.4461 0.015833 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Problem 2 is derivatives and elasticities
2 dimensional for loop for matrices
1st step: create J times J matrix of zeros D
D <- matrix(0, nrow = J, ncol = J)
for (i in 1:J){
for (j in 1:J){
# Figure out the indices for zeros
if (i==j) {
D[i,j] = 1 ## Write the co
ect formula with co
ect indices
} else if (j == i+1) {
D[i,j] = -1
} else if (j == i-1) {
D[i,j] = -2
} else {
D[i,j] = 0
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here