Grouped equal-frequency quartile bins (Stata's xtile ..., nq(4))
Source: R/utils-panel.R
quartile_bin.RdThin wrapper around statar::xtile() documenting the contract this package
relies on: NA in, NA out; non-missing values split into n groups of
(approximately) equal size, numbered 1..n. See
Pseudocode/00_conventions.md's QUARTILE primitive. Callers are
responsible for applying this only within already-grouped data (this
package additionally imposes a minimum group size of 50 before calling this
at all — see compute_predictors()).
Details
Stata's own xtile is confirmed to use a percentile algorithm equivalent
to R's quantile(type = 2) (see percentile_stata() and its source
comment); statar::xtile() is a separate, independent R reimplementation,
and its exact tie-breaking at quartile boundaries has not been verified
here to match Stata's bit-for-bit. For this package's use (classifying
scalers into descriptive predictor-quartile groups), this is a low-stakes
residual risk — a handful of firms sitting exactly on a cutpoint could
land in an adjacent bin — flagged rather than silently assumed away.