Each user's metric is a city shock plus the user's own noise
The practice data is built from that same picture.
import numpy as np
def practice_data(seed, city_sd):
rng = np.random.default_rng(seed)
cluster = np.repeat(np.arange(40), 50)
treat = rng.permutation(np.r_[np.ones(20), np.zeros(20)])[cluster]
shock = rng.normal(0, city_sd, 40)[cluster]
y = 10 + 0.5 * treat + shock + rng.normal(0, 2, 2000)
return y, treat, cluster
y, treat, cluster = practice_data(0, 1.5)
means = np.array([y[cluster == g].mean() for g in range(40)])
inside = np.array([y[cluster == g].std() for g in range(40)])
print(f"users inside one city spread by {inside.mean():.2f}")
print(f"the 40 city means spread by {means.std():.2f}")
users inside one city spread by 1.97
the 40 city means spread by 1.39
This is how the practice data is made. cluster holds each user's city id, 0 to 39, fifty users each. rng.normal(0, city_sd, 40) draws one shock per city, and indexing with [cluster] copies it to the city's 50 users. The coin flips are copied the same way.
The spread here is the standard deviation. Users inside a city spread by about 2, their own noise. If users were independent, a mean of 50 of them would spread by only . The city means spread by 1.39. Most of that is the city shock, which every user in the city shares.
In symbols:
In words: user in city gets the base level (10 in the code), plus the effect (0.5) when the city's flag is 1, plus the city's shock , plus the user's own noise . The shocks have variance , 1.5 squared in the code, and the users' own noise has variance , 2 squared. There are cities of users, so users in all.