Calculate GDP
# the order is Dairy, Coffee, and Flower
p1 = c(10, 20, 20)
q1 = c(80, 150, 200)
p2 = c(16, 20, 28)
q2 = c(85, 165, 150)
p3 = c(20, 35, 20)
q3 = c(85, 165, 200)
Price as a Fisher index
# Calculate chain Weight
P_t_t1 = function(pt, qt, pt1, qt1) {
sqrt((pt1 %*% qt) * (pt1 %*% qt1)/(pt %*% qt)/(pt %*% qt1))
}
# Period 1 to 2 P_1_2= P_t_t1(p1,q1,p2,q2)
P_2_3 = P_t_t1(p2, q2, p3, q3)
P_2_3
## [,1]
## [1,] 1.15
Quantity as a Fisher index
# Calculate chain Weight
Q_t_t1 = function(pt, qt, pt1, qt1) {
sqrt((pt %*% qt1) * (pt1 %*% qt1)/(pt %*% qt)/(pt1 %*% qt))
}
# Period 1 to 2
Q_1_2 = Q_t_t1(p1, q1, p2, q2)
Q_1_2
## [,1]
## [1,] 0.9067
# Period 2 to 3
Q_2_3 = Q_t_t1(p2, q2, p3, q3)
Q_2_3
## [,1]
## [1,] 1.126
realGDP1 = 1
realGDP2 = realGDP1 * Q_1_2
realGDP2
## [,1]
## [1,] 0.9067
realGDP3 = realGDP2 * Q_2_3
realGDP3
## [,1]
## [1,] 1.021
Nominal GDP and GDP deflator
GDP_3 = 6300/realGDP3 * 100
GDP_3
## [,1]
## [1,] 616936