Skip to content

6.9 Enums

Matteo Guido Richiardi edited this page Feb 1, 2026 · 1 revision

An enum is a special class that represents a group of constants (unchangeable variables). One way to think about enums for users familiar with, for example, Stata, is as of categorical variables – each category that the variable can take must be specified in the enum. In general, enums are well suited for use with values that we know are not going to change.

For example, to define a variable Gender that can take either Male or Female values, we define an enum Gender in the model.enums package:

Gender Enum Example

We can then, for example, specify a variable gender in Person class, which will only ever take one of the values specified in the enum:

Gender Variable Example

For a more detailed tutorial on enums we recommend following W3Schools and Oracle's tutorial.

Clone this wiki locally