Examples & Use Cases

Practical examples demonstrating how to use NARDL-Fourier for different research applications.

Example 1: Energy Economics

Analyzing asymmetric effects of oil prices on coal consumption following the methodology of Zaghdoudi et al. (2023).

Python
import pandas as pd import numpy as np from nardl_fourier import NARDL, FourierNARDL, BootstrapNARDL, ResultsTable # Load energy data # Assuming annual data for a country df = pd.read_excel('energy_data.xlsx') # Variables: # - coal: Coal consumption per capita (log) # - oil_price: Real oil price (log) # - gdp: GDP per capita (log) # - gdp2: Squared GDP to capture EKC print("Data preview:") print(df.head()) print(f"\\nObservations: {len(df)}") # Step 1: Fit Standard NARDL print("\\n" + "="*60) print("STANDARD NARDL MODEL") print("="*60) nardl = NARDL( data=df, depvar='coal', exog_vars=['gdp', 'gdp2'], decomp_vars=['oil_price'], maxlag=4, ic='AIC', case=3 ) print(nardl.summary()) # Step 2: Fit Fourier NARDL (account for structural breaks) print("\\n" + "="*60) print("FOURIER NARDL MODEL") print("="*60) fnardl = FourierNARDL( data=df, depvar='coal', exog_vars=['gdp', 'gdp2'], decomp_vars=['oil_price'], maxlag=4, max_freq=3, ic='AIC' ) print(f"Optimal Fourier frequency: k* = {fnardl.best_freq}") print(fnardl.summary()) # Step 3: Bootstrap test for robust inference print("\\n" + "="*60) print("BOOTSTRAP FOURIER NARDL") print("="*60) bnardl = BootstrapNARDL( data=df, depvar='coal', exog_vars=['gdp', 'gdp2'], decomp_vars=['oil_price'], maxlag=4, max_freq=3, n_bootstrap=1000, random_state=42 ) print(bnardl.summary()) print("\\nCointegration Decision:") print(bnardl.cointegration_decision())

Interpretation

If the long-run multipliers show L⁺ ≠ L⁻ and the Wald test confirms asymmetry, coal consumption responds differently to oil price increases versus decreases. This has important policy implications for energy transitions.

Example 2: Exchange Rate Pass-Through

Examining asymmetric exchange rate pass-through to import prices.

Python
import pandas as pd from nardl_fourier import BootstrapNARDL, NARDLPlots # Variables: # - import_price: Import price index (log) # - exchange_rate: Nominal exchange rate (log) # - producer_price: Foreign producer prices (log) df = pd.read_csv('erpt_data.csv') # Model: Import prices ~ Exchange rate (asymmetric) + Foreign prices model = BootstrapNARDL( data=df, depvar='import_price', exog_vars=['producer_price'], decomp_vars=['exchange_rate'], maxlag=4, max_freq=2, n_bootstrap=1000 ) # Results summary print(model.summary()) # Extract key pass-through coefficients lr = model.long_run['exchange_rate'] print("\\nExchange Rate Pass-Through (ERPT):") print(f" Depreciation (L⁺): {lr['positive']['coefficient']:.4f}") print(f" Appreciation (L⁻): {lr['negative']['coefficient']:.4f}") # Interpretation if abs(lr['positive']['coefficient']) > abs(lr['negative']['coefficient']): print("\\n→ Depreciations have LARGER effects on import prices") print(" (Firms pass through cost increases more readily)") else: print("\\n→ Appreciations have LARGER effects on import prices") print(" (Consumers benefit more from currency appreciation)") # Plot dynamic multipliers plots = NARDLPlots(model) fig = plots.dynamic_multipliers('exchange_rate', horizon=20) fig.savefig('erpt_multipliers.png', dpi=300)

Example 3: Comparing All Three Models

A systematic comparison of NARDL, Fourier NARDL, and Bootstrap NARDL.

Python
import pandas as pd from nardl_fourier import NARDL, FourierNARDL, BootstrapNARDL # Load data df = pd.read_csv('data.csv') # Common specification spec = { 'data': df, 'depvar': 'y', 'exog_vars': ['z'], 'decomp_vars': ['x'], 'maxlag': 4, 'ic': 'AIC' } # Fit all three models m1 = NARDL(**spec) m2 = FourierNARDL(**spec, max_freq=3) m3 = BootstrapNARDL(**spec, max_freq=3, n_bootstrap=1000) # Comparison table comparison = pd.DataFrame({ 'Metric': ['R²', 'Adj. R²', 'AIC', 'F-stat', 'Bounds Decision', 'ECT (ρ)'], 'NARDL': [ f"{m1.model.rsquared:.4f}", f"{m1.model.rsquared_adj:.4f}", f"{m1.best_ic:.2f}", f"{m1.bounds_test['f_statistic']:.4f}", m1.bounds_test['decision']['F_5%'], f"{m1.ect['coefficient']:.4f}" ], 'Fourier NARDL': [ f"{m2.model.rsquared:.4f}", f"{m2.model.rsquared_adj:.4f}", f"{m2.best_ic:.2f}", f"{m2.bounds_test['f_statistic']:.4f}", m2.bounds_test['decision']['F_5%'], f"{m2.ect['coefficient']:.4f}" ], 'Bootstrap NARDL': [ f"{m3.model.rsquared:.4f}", f"{m3.model.rsquared_adj:.4f}", f"{m3.best_ic:.2f}", f"{m3.bounds_test['f_statistic']:.4f}", m3.bootstrap_results['overall'], f"{m3.ect['coefficient']:.4f}" ] }) print("Model Comparison:") print(comparison.to_string(index=False))

Example 4: Generating Publication Tables

Export results in LaTeX format for academic papers.

Python
from nardl_fourier import BootstrapNARDL, ResultsTable # Fit model model = BootstrapNARDL(...) # Create table generator table = ResultsTable(model) # Individual tables as DataFrames reg_df = table.regression_table() # Full regression lr_df = table.long_run_table() # Long-run multipliers sr_df = table.short_run_table() # Short-run coefficients diag_df = table.diagnostics_table() # Diagnostic tests bounds_df = table.bounds_test_table() # Bounds test wald_df = table.wald_test_table() # Asymmetry tests # Export to LaTeX table.to_latex('results_all.tex') # Or get individual LaTeX tables latex_lr = table.long_run_table(output='latex') print(latex_lr) # Bootstrap test summary if model.bootstrap_test: boot_df = model.bootstrap_test.summary_table() print("\\nBootstrap Cointegration Tests:") print(boot_df.to_latex(index=False))
💡
Output Formats

All table methods support output formats: 'dataframe' (default), 'latex', 'html', and 'markdown'.

Sample LaTeX Output

LaTeX
\begin{table}[htbp] \centering \caption{Long-Run Multipliers} \label{tab:long-run_multipliers} \begin{tabular}{lcccccc} \toprule Variable & Coeff. & Std. Error & t-stat & p-value & 95\% CI \\ \midrule oil\_price$^{+}$ & 0.4521 & 0.0823 & 5.49 & 0.0000 & [0.290, 0.614] \\ oil\_price$^{-}$ & 0.2134 & 0.0756 & 2.82 & 0.0068 & [0.064, 0.363] \\ \bottomrule \end{tabular} \end{table}