Worker#

class bamengine.roles.worker.Worker(employer, employer_prev, wage, periods_left, contract_expired, fired, job_apps_head, job_apps_targets)[source]#

Bases: Role

Worker role for households.

Represents the employment and wage state for households. Each array index corresponds to a household ID (0 to n_households-1).

Parameters:
  • employer (Idx1D) – Current employer firm ID (-1 if unemployed).

  • employer_prev (Idx1D) – Previous employer firm ID (for tracking job switches).

  • wage (Float1D) – Current wage earned from employment.

  • periods_left (Int1D) – Periods remaining in current employment contract.

  • contract_expired (Bool1D) – True if current contract has expired.

  • fired (Bool1D) – True if worker was fired this period.

  • job_apps_head (Idx1D) – Queue head pointer for job applications.

  • job_apps_targets (Idx2D) – Queue of firm IDs to apply to, shape (n_households, max_M).

Examples

Access from simulation:

>>> import bamengine as bam
>>> sim = bam.Simulation.init(n_households=500, seed=42)
>>> wrk = sim.wrk
>>> wrk.wage.shape
(500,)
>>> wrk.employer.shape
(500,)

Check employment status:

>>> import numpy as np
>>> employed = wrk.employed
>>> employed.sum()
480

Find unemployed workers:

>>> unemployed_mask = ~wrk.employed
>>> unemployed_ids = np.where(unemployed_mask)[0]
>>> unemployed_ids.shape
(20,)

Calculate average wage of employed workers:

>>> employed_wages = wrk.wage[wrk.employed]
>>> employed_wages.mean()
1.15

Check contract expiration:

>>> expiring_soon = wrk.periods_left <= 1
>>> expiring_soon.sum()
35

Notes

The Worker role is one of two roles assigned to households:

  • Worker: employment and labor supply

  • Consumer: consumption and savings (see Consumer)

Employment status is computed via the employed property, which checks if employer >= 0. Unemployed workers have employer = -1.

See also

Consumer

Consumption role for households

Employer

Labor hiring role for firms

labor_market

Labor market logic

employer#

Current employer firm ID (-1 if unemployed).

employer_prev#

Previous employer firm ID (for tracking job switches).

wage#

Current wage earned from employment.

periods_left#

Periods remaining in current employment contract.

contract_expired#

Whether the current contract has expired this period.

__init__(employer, employer_prev, wage, periods_left, contract_expired, fired, job_apps_head, job_apps_targets)#
name = 'Worker'#
fired#

Whether the worker was fired this period.

job_apps_head#

Queue head pointer for job applications.

job_apps_targets#

Queue of firm IDs to apply to, shape (n_households, max_M).

property employed#

Compute employment status from employer ID.

Returns True for workers with employer >= 0, False otherwise.

Returns:

Boolean array where True indicates employed, False indicates unemployed.

Return type:

Bool1D

Examples

>>> import bamengine as bam
>>> sim = bam.Simulation.init(n_households=500, seed=42)
>>> wrk = sim.wrk
>>> employed_count = wrk.employed.sum()
>>> employed_count
480
>>> unemployment_rate = 1.0 - (employed_count / 500)
>>> unemployment_rate
0.04