est, se, df = city_means_test(y, treat, cluster)
print(f"estimate {est:.3f} SE {se:.3f} {df} degrees of freedom")
estimate -0.155 SE 0.452 38 degrees of freedom
The simplest valid analysis collapses each city to one number, its mean. Then it runs an ordinary two-sample t-test on the G means, with G−2 degrees of freedom. The unit of analysis becomes the unit of randomization, and the problem is gone.
The city means are independent of each other. With equal city sizes and normal noise, this test is exact at any number of cities: the city-means column of the few-cities table held 5.0% at every row.
On the practice data it gives the same estimate, -0.155, and a standard error of 0.452, against the clustered 0.446.
In the editor, write city_means_test(y, treat, cluster): one mean per city, then an ordinary t-test.