Skip to content

mtelek/threshold_regression_model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Threshold Regression for the Spanish Housing Market

This repository contains an R implementation of a panel threshold regression framework inspired by Dong, Hui, and Jia (2017), adapted to Spanish regional housing market data.

The original Dong, Hui, and Jia (2017) study focuses on 35 Chinese cities. This project applies the same empirical logic to Spain, using panel data across regions and years.

Repository Structure

  • R/analysis.R: Main end-to-end analysis script.
  • scripts/install_deps.sh: OS-level dependency installer for Linux/macOS.
  • data/: Input data folder. The script expects Spain_Dataset_2008_2019.xlsx here.

Dependencies

1. System dependencies (Linux/macOS first)

Before running the R script on Linux or macOS, install system dependencies from the project root:

bash scripts/install_deps.sh

What this installs:

  • Linux: gfortran, zlib1g-dev
  • macOS: gcc (includes Fortran toolchain)

These are needed because several R packages are compiled from source.

2. R package dependencies

The analysis uses the following R packages:

  • plm
  • readxl
  • lmtest
  • sandwich
  • psych
  • writexl
  • here

In R/analysis.R, installation commands are provided as commented lines. Uncomment them for first-time setup, run once, then keep only the library(...) calls for routine use.

How to Run

  1. Clone the repository.
  2. On Linux/macOS, run:
bash scripts/install_deps.sh
  1. Open R/analysis.R.
  2. Run the script (for example, line-by-line with Ctrl+Enter or as a full script).

Method and Model Overview

The script implements a panel-data threshold regression design with fixed effects and robust inference.

Baseline model

The conceptual baseline model in levels is:

$$\ln(Consumption)_{it} = \alpha_i + \beta_1 \ln(HousePrice)_{it} + \beta_2 \ln(Income)_{it} + \varepsilon_{it}$$

After panel unit-root testing (LLC), the empirical model is estimated in first differences:

$$\Delta \ln(Consumption)_{it} = \beta_1 \Delta \ln(HousePrice)_{it} + \beta_2 \Delta \ln(Income)_{it} + \varepsilon_{it}$$

where first differencing removes time-invariant regional effects.

Threshold models

The script then allows the housing-price coefficient to differ by regime, where regimes are determined by a threshold variable:

  • Affordability
  • Financial Development

Single-threshold specifications:

$$\Delta \ln(Consumption)_{it} = \beta_1 \Delta \ln(HousePrice)_{it} I(Affordability_{it} \leq \gamma_1) \\\ \quad + \beta_2 \Delta \ln(HousePrice)_{it} I(Affordability_{it} > \gamma_1) \\\ \quad + \beta_3 \Delta \ln(Income)_{it} + \varepsilon_{it}$$ $$\Delta \ln(Consumption)_{it} = \beta_1 \Delta \ln(HousePrice)_{it} I(FinancialDevelopment_{it} \leq \gamma_2) \\\ \quad + \beta_2 \Delta \ln(HousePrice)_{it} I(FinancialDevelopment_{it} > \gamma_2) \\\ \quad + \beta_3 \Delta \ln(Income)_{it} + \varepsilon_{it}$$

The threshold values are selected by grid search, choosing the value that minimizes residual sum of squares (RSS).

Inference strategy

The workflow includes:

  • Panel unit-root checks (LLC) and first differencing
  • Baseline fixed-effects panel regression as benchmark
  • Grid search for threshold estimation
  • Hansen-style bootstrap test for threshold significance (500 replications)
  • Optional second-threshold search and test
  • Robust (HC1) standard errors for coefficient inference
  • Savings excluded from the specification due to data limitations and endogeneity concerns
  • Combined Affordability × Financial Development regimes are checked; in this implementation, sparse regime counts can prevent reliable combined-model estimation

Output tables

The script exports descriptive statistics, unit-root results, threshold interval summaries, and model comparison tables to Excel files.

Relation to Dong, Hui, and Jia (2017)

This project is an implementation inspired by Dong, Hui, and Jia (2017):

  • Original context: 35 Chinese cities
  • This repository: Spanish regional panel application

So the empirical template is consistent with Dong, Hui, and Jia (2017), but the data context and resulting estimates are specific to Spain.

Paper link: Dong, Hui, and Jia (2017) - How does housing price affect consumption in China: Wealth effect or substitution effect?

Formal citation:

Dong, Zhaoyingzi, Eddie C.M. Hui, and ShengHua Jia. 2017. "How Does Housing Price Affect Consumption in China: Wealth Effect or Substitution Effect?" Cities 64: 1-8. doi:10.1016/j.cities.2017.01.006.

About

Panel data project in R analyzing how housing prices influence household consumption in Spain, with results benchmarked against a leading published framework (Dong, Hui, and Jia, 2017).

Topics

Resources

Stars

Watchers

Forks

Contributors