A small package for calculating the matrices in Shiller (1991) that serve as the foundation for many repeat-sales price indexes. Builds on the ‘rsi’ package by Kirby-McGregor and Martin (2019).
install.package("rsmatrix")
Get the development version from GitHub.
::install_github("marberts/rsmatrix") devtools
library(rsmatrix)
# Make some data
<- data.frame(id = c(1, 1, 1, 2, 2),
sales date = c(1, 2, 3, 1, 3),
price = c(1, 3, 2, 1, 1))
# Turn into sales pairs
c("date_prev", "price_prev")] <- sales[rs_pairs(sales$date, sales$id), c("date", "price")]
sales[
<- subset(sales, date > date_prev)) (sales
## id date price date_prev price_prev
## 2 1 2 3 1 1
## 3 1 3 2 2 3
## 5 2 3 1 1 1
# Calculate matrices
<- with(sales, rs_matrix(date, date_prev, price, price_prev))
matrix_constructor <- sapply(c("Z", "X", "y", "Y"), matrix_constructor)
matrices
$Z matrices
## 2 3
## 1 1 0
## 2 -1 1
## 3 0 1
$X matrices
## 2 3
## 1 3 0
## 2 -3 2
## 3 0 1
# Calculate the GRS index in Bailey, Muth, and Nourse (1963)
<- with(matrices, solve(crossprod(Z), crossprod(Z, y))[, 1])
b <- exp(b) * 100) (grs
## 2 3
## 238.1102 125.9921
# Calculate the ARS index in Shiller (1991)
<- with(matrices, solve(crossprod(Z, X), crossprod(Z, Y))[, 1])
b <- 100 / b) (ars
## 2 3
## 240.0000 133.3333
Kirby-McGregor, M., and Martin, S. (2019). An R package for calculating repeat-sale price indices. Romanian Statistical Review, 3:17-33.
Shiller, R. J. (1991). Arithmetic repeat sales price estimators. Journal of Housing Economics, 1(1):110-126.