Example usage

Here we will demonstrate how to use ivxj package to compute the IVXJ estimates and the corresponding \(t\)-statistics for unbalanced panel data under a simple regression specification.

We use the baseline sample of Greenwood et al. (2022), which is an unbalanced panel that covers 42 countries from 1950 to 2016 annually. They investigate the empirical association via the panel local projection:

\[y_{i,t+h} = \mu_{y,i}^{(h)} + \beta^{(h)*} \cdot x_{i,t}^{\mathrm{diff}} + e_{i,t+h},\quad h=1,2,3.\]

The dependent variable \(y_{i,t+h}\) is a binary indicator of financial crisis occurring in country \(i\) in any year between year \(t+1\) and year \(t+h\), and the regressor \(x_{i,t}^{\mathrm{diff}}\) is the three-year debt growth relative to either GDP or CPI. And we run the regression when \(h = 1\) in this example.

Four measures of normalized debt are used, and in this example, we use this measure: Ratio of private debt to GDP (\(\mathit{Debt}^{\mathit{Priv}}/\mathit{GDP}\)).

For IVX we set \(c_{z}=-1\) and \(\theta=0.95\) as in our paper, thereby \(\rho_{z}=1-1 / \max_{i \leq n} T_{i}^{0.95}\), where \(T_{i}\) is the time span of country \(i\) in this unbalanced panel.

Import

import ivxj

print(ivxj.__version__)
0.1.0

Data Processing

The data is downloaded from here. The Data.csv can be found in this folder.

import pandas as pd
data = pd.read_csv('Data.csv')

The dependent variable is crisis_ind_bvx and the regressor is debt_to_gdp_private_d3.

data_selected = data[["country", "year", "crisis_ind_bvx", "debt_to_gdp_private_d3"]].dropna()

# delete individual time series less than 3 observations
country_counts = data_selected["country"].value_counts()
valid_countries = country_counts[country_counts > 2].index
data_filtered = data_selected[data_selected["country"].isin(valid_countries)]

Estimation

import numpy as np
rhoz = np.float64(0.980174328998269)
btaHat, btaHatDebias, se, rhoHat = ivxj.ivxj(data_filtered, rhoz)

btaHat is the IVX estimate for \(\beta^{(h)*}\).

btaHat
np.float64(0.0029654842208844427)

The IVXJ estimate is btaHatDebias. Below, we print both the IVXJ estimate and its corresponding standard error se.

print("IVXJ Estimate:", btaHatDebias)
print("Standard Error:", se)
IVXJ Estimate: 0.003058926878738317
Standard Error: 0.0007471981592453963

Finally, we calculate the \(t\)-statistic for the hypothesis test.

print("t-statistics:", btaHatDebias / se)
t-statistics: 4.093862974485324