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.
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 expectsSpain_Dataset_2008_2019.xlsxhere.
Before running the R script on Linux or macOS, install system dependencies from the project root:
bash scripts/install_deps.shWhat this installs:
- Linux:
gfortran,zlib1g-dev - macOS:
gcc(includes Fortran toolchain)
These are needed because several R packages are compiled from source.
The analysis uses the following R packages:
plmreadxllmtestsandwichpsychwritexlhere
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.
- Clone the repository.
- On Linux/macOS, run:
bash scripts/install_deps.sh- Open
R/analysis.R. - Run the script (for example, line-by-line with Ctrl+Enter or as a full script).
The script implements a panel-data threshold regression design with fixed effects and robust inference.
The conceptual baseline model in levels is:
After panel unit-root testing (LLC), the empirical model is estimated in first differences:
where first differencing removes time-invariant regional effects.
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:
The threshold values are selected by grid search, choosing the value that minimizes residual sum of squares (RSS).
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
The script exports descriptive statistics, unit-root results, threshold interval summaries, and model comparison tables to Excel files.
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.
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.