group is a Stata command that creates categorical variables from multiple logical conditions. Instead of forcing you to choose between overlapping categories, it uses a power-of-two indexing system to elegantly handle cases where observations meet multiple criteria simultaneously. Perfect for data validation, complex categorization, and any scenario where traditional mutually exclusive categories fall short.
- Handles Overlapping Conditions: Intelligently manages cases where an observation meets multiple criteria
- Robust Categorization: Uses a power-of-two indexing system to ensure every combination of conditions gets a unique, interpretable value
- Flexible Syntax: Allows custom delimiters to avoid conflicts with condition or label text
- Descriptive Labels and Notes: Automatically generates clear value labels and detailed notes for combined categories
- Programmatic Access: Returns detailed results in
r()for use in other scripts or validation checks
First, install the required dependency:
ssc install tuples, replaceThen install group directly from GitHub:
net install group, from("https://raw.githubusercontent.com/hafizarfyanto/group/main/")To ensure you have the most recent features and bug fixes:
net install group, replace from("https://raw.githubusercontent.com/hafizarfyanto/group/main/")If you need to remove the package:
ado uninstall groupIf the standard uninstall method doesn't work (e.g., if group was installed multiple times), follow these steps:
-
Run:
ado dir groupin Stata command window -
Note all index numbers shown for group installations
-
Uninstall packages using index numbers in descending order:
ado uninstall [highest_index] ado uninstall [next_index]
* Load sample data
sysuse auto, clear
* Create categories based on overlapping conditions
group, rules(mpg > 22 :: "Efficient" ||| price < 5000 :: "Affordable") generate(car_cat)
* See the results
table car_cat
label list CAR_CAT
notes car_catOutput explanation:
- Value
0: Neither efficient nor affordable - Value
1: Efficient only (mpg > 22) - Value
2: Affordable only (price < 5000) - Value
3: Both efficient AND affordable (1 + 2 = 3)
This power-of-two system ensures every possible combination gets a unique, interpretable value.
group, rules(string) [generate(newvar) label pairdelimiter(string) labdelimiter(string)]Main Options:
rules(string): Define conditions and labels usingcondition :: label ||| condition :: labelformatgenerate(newvar): Specify custom variable name (default:_group)label: Use descriptive text for value labels instead of numeric codespairdelimiter(string): Custom separator between condition-label pairs (default:|||)labdelimiter(string): Custom separator between condition and label (default:::)
For complete documentation, see: help group
- Requires Stata 16 or newer
- Requires the user-written
tuplescommand (install withssc install tuples)
Report issues or suggest improvements:
GitHub Issues
If you use group in your research, please cite:
Plain Text:
Hafiz Arfyanto (2025). group: Categorical Variables from Logical Conditions. Version 1.0.0.
Retrieved from https://github.com/hafizarfyanto/groupBibTeX Entry:
@misc{arfyanto2025group,
author = {Hafiz Arfyanto},
title = {group: Categorical Variables from Logical Conditions},
version = {1.0.0},
year = {2025},
url = {https://github.com/hafizarfyanto/group},
note = {Stata command for creating categorical variables from multiple logical conditions}
}help group