trend

trend(
    data,
    variable,
    *,
    by=None,
    units=True,
    stat='mean',
    max_units=400,
    title=None,
    ref=None,
)

A variable over time: its mean (or median) across units, with a band, and each unit’s path.

Parameters

Name Type Description Default
data A dataset id, or a panel with geo_id and year, e.g. from load required
variable str The numeric column to follow required
by str | None One line per group: a column of the table, or a coarser scale of its units (e.g. the first-level administrative scale), whose names are added None
units bool Draw each unit’s own trajectory as a thin grey line behind the summary True
stat str "mean" (band: one standard error on each side) or "median" (band: the interquartile range) 'mean'
max_units int Draw at most this many unit trajectories (a reproducible random sample when there are more); the statistics always use every unit 400
title str | None The figure title None

Notes

The panel needs at least two years with data.

Returns

Name Type Description
TrendResult A result with .df (one row per year and group: the statistic in a column named mean or median, the band in lower and upper, and n units), .fig, .first and .last (years), .value_first, .value_last and .change (the statistic across all units), .share_rising (share of units with data in both years that ended higher), .n_units, .notes and .interpret().

Example

!pip install -q geo4bolivia
import geo4bolivia as geo

res = geo.trend("ntl", "ln_NTLpc")
print(res.interpret())
res.fig

Between 2012 and 2020, the mean of Log night-time lights per capita across 331 units rose from 13.1 to 13.9 (a change of +0.812).

94% of the units with data in both years ended higher than they started: the summary line describes the typical unit, not every unit.

The band is one standard error on each side of the mean: how precisely the average is known, not how much units differ.

These are associations, not causal effects. A causal reading needs a research design.