% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xtbhst.R
\name{xtbhst}
\alias{xtbhst}
\title{Bootstrap Slope Heterogeneity Test for Panel Data}
\usage{
xtbhst(
  formula,
  data,
  id,
  time,
  reps = 999L,
  blocklength = NULL,
  partial = NULL,
  csa = NULL,
  csa_lags = 0L,
  constant = TRUE,
  seed = NULL
)
}
\arguments{
\item{formula}{A formula of the form \code{y ~ x1 + x2 + ...} specifying
the dependent variable and regressors.}

\item{data}{A data frame containing the panel data.}

\item{id}{A character string specifying the name of the cross-sectional
identifier variable.}

\item{time}{A character string specifying the name of the time variable.}

\item{reps}{Integer. Number of bootstrap replications (default: 999).}

\item{blocklength}{Integer. Block length for the block bootstrap. If
\code{NULL} (default), set automatically to \code{floor(2 * T^(1/3))}
where T is the number of time periods.}

\item{partial}{Optional formula specifying variables to be partialled out.
For example, \code{~ z1 + z2}.}

\item{csa}{Optional formula specifying variables for which cross-sectional
averages should be computed and included. Used to handle cross-sectional
dependence following Pesaran (2006).}

\item{csa_lags}{Integer. Number of lags of the cross-sectional averages
to include (default: 0).}

\item{constant}{Logical. If \code{TRUE} (default), include a constant
(partialled out).}

\item{seed}{Optional integer seed for reproducibility.}
}
\value{
An object of class \code{"xtbhst"} containing:
\describe{
\item{delta}{The Delta test statistic.}
\item{delta_adj}{The adjusted Delta test statistic.}
\item{pval}{Bootstrap p-value for the Delta statistic.}
\item{pval_adj}{Bootstrap p-value for the adjusted Delta statistic.}
\item{blocklength}{The block length used in the bootstrap.}
\item{reps}{Number of bootstrap replications.}
\item{N}{Number of cross-sectional units.}
\item{T}{Number of time periods.}
\item{K}{Number of regressors.}
\item{beta_i}{Matrix of individual slope estimates (N x K).}
\item{beta_fe}{Vector of weighted fixed effects (pooled) estimates.}
\item{delta_stars}{Vector of bootstrap Delta statistics.}
\item{delta_adj_stars}{Vector of bootstrap adjusted Delta statistics.}
\item{call}{The matched call.}
}
}
\description{
Implements the bootstrap slope heterogeneity test based on
Blomquist and Westerlund (2015). Tests the null hypothesis that slope
coefficients are homogeneous across cross-sectional units.
}
\details{
The test is based on the following Delta statistic:
\deqn{\Delta = \sqrt{N} \frac{\tilde{S}/N - K}{\sqrt{2K}}}
where \eqn{\tilde{S}} is a weighted sum of squared deviations of
individual slope estimates from the weighted pooled estimate.

The adjusted Delta statistic corrects for small sample bias:
\deqn{\Delta_{adj} = \sqrt{N} \frac{\tilde{S}/N - K}{\sqrt{V}}}
where \eqn{V = 2K(T-K-K_{partial}-1)/(T-K_{partial}+1)}.

Under the null hypothesis of slope homogeneity, both statistics
are asymptotically standard normal. The bootstrap procedure provides
finite-sample p-values.

The function requires a strongly balanced panel (all units observed
for all time periods).
}
\examples{
\donttest{
# Generate example panel data
set.seed(123)
N <- 20  # cross-sectional units
T_periods <- 30  # time periods

# Homogeneous slopes (H0 is true)
data_hom <- data.frame(
  id = rep(1:N, each = T_periods),
  time = rep(1:T_periods, N),
  x = rnorm(N * T_periods)
)
data_hom$y <- 1 + 0.5 * data_hom$x + rnorm(N * T_periods)

# Test for slope heterogeneity
result <- xtbhst(y ~ x, data = data_hom, id = "id", time = "time",
                 reps = 199, seed = 42)
print(result)
summary(result)
}

}
\references{
Blomquist, J., & Westerlund, J. (2015).
Panel bootstrap tests of slope homogeneity.
\emph{Empirical Economics}, 48(1), 1191-1204.
\doi{10.1007/s00181-015-0978-z}

Pesaran, M. H. (2006).
Estimation and inference in large heterogeneous panels with a
multifactor error structure.
\emph{Econometrica}, 74(4), 967-1012.
\doi{10.1111/j.1468-0262.2006.00692.x}
}
