---
title: "Sampling and Inference"
book: "University Economics — Year 1"
subject: economics
language: en
chapter: 31
exercises: 12
source: https://one-course.com/books/economics/3/en/chapter/31-sampling-and-inference
license: CC-BY-NC-SA-4.0
credit: "One Economics Book, One Course (one-course.com)"
---

# Chapter 31 — Sampling and Inference

The US unemployment rate is estimated each month from a survey of about 60,000 households. At a rate of around $6\%$, the statistical office gives a $90\%$ [confidence interval](#def-b1-sampling-and-inference-confidence-interval) of about $\pm 0.3$ point for the change from one month to the next. A rise of $0.1$ point, reported as news, cannot be told apart from the noise of drawing a different sample. This chapter is about what one sample can say about a [population](#def-b1-sampling-and-inference-population): [estimators](#def-b1-sampling-and-inference-estimator) and their errors, [confidence intervals](#def-b1-sampling-and-inference-confidence-interval), tests, and how surveys are designed and weighted.

![Unemployment rate, ages 15–74, per cent of the labour force, quarterly, 2010–2026: seasonally adjusted (thin) and trend-cycle (thick), Germany (left) and Estonia (right).](https://one-course.com/images/onecourse/chapters/economics-3/b1-sampling-and-inference/fig-44c6b26f1a6c.svg)

*Unemployment rate, ages 15–74, per cent of the labour force, quarterly, 2010–2026: seasonally adjusted (thin) and trend-cycle (thick), Germany (left) and Estonia (right). Source: Eurostat, une_rt_q*

Both series are survey estimates. Germany’s seasonally adjusted rate stays within a standard deviation of $0.07$ point of its trend; Estonia’s jumps around it with a standard deviation of $0.51$ point, and moves by $0.72$ point from one quarter to the next on average, against $0.13$ in Germany. Part of the gap is that Estonia’s labour market moves more; part is that the survey of a small country samples far fewer people, and its estimates are noisier.

**You already know.**

[Sampling distributions](https://one-course.com/books/economics/3/en/chapter/30-random-variables-for-econometrics#def-b1-random-variables-for-econometrics-sampling-distribution), the normal and Student’s $t$ laws and the central limit theorem are [Chapter 30](https://one-course.com/books/economics/3/en/chapter/30-random-variables-for-econometrics#ch-b1-random-variables-for-econometrics); [conditional means](https://one-course.com/books/economics/3/en/chapter/29-describing-data#def-b1-describing-data-conditional-mean) are [Chapter 29](https://one-course.com/books/economics/3/en/chapter/29-describing-data#ch-b1-describing-data). The unemployment survey and its definitions were met at school.

## 31.1 Population and sample

**Definition 31.1 (Population parameter).**

A *population*, in statistics, is the set of units about which a question is asked; a *population parameter* is a number that describes it, such as its mean $\mu$ or its unemployment rate. It is fixed and unknown. (A model’s parameters, [Chapter 1](https://one-course.com/books/economics/3/en/chapter/1-models-and-data#ch-b1-models-and-data), are a different use of the word.)

**Definition 31.2 (Estimator, unbiased, consistent).**

An *estimator* is a rule that turns a sample into a guess of a parameter $\theta$; the number it gives in one sample is an estimate. An estimator $\hat\theta_n$ is *unbiased* when $\E[\hat\theta_n] = \theta$, and *consistent* when, for every $\varepsilon > 0$, $P(|\hat\theta_n - \theta| > \varepsilon) \to 0$ as the sample size $n$ grows.

![](https://one-course.com/images/onecourse/chapters/economics-3/b1-sampling-and-inference/fig-3ee06c76f9a0.svg)

## 31.2 Estimators: bias, variance, consistency

**Proposition 31.3 (The sample mean).**

For independent draws with mean $\mu$ and variance $\sigma^2$, the sample mean $\bar X_n$ is unbiased and consistent for $\mu$.

**Proof.** $\E[\bar X_n] = \frac1n\sum_i \E[X_i] = \mu$. Its variance is $\sigma^2/n$ ([Chapter 30](https://one-course.com/books/economics/3/en/chapter/30-random-variables-for-econometrics#ch-b1-random-variables-for-econometrics)), so by Chebyshev’s inequality $P(|\bar X_n - \mu| > \varepsilon) \le \sigma^2/(n\varepsilon^2) \to 0$. ∎

**Proposition 31.4 (Dividing by n−1n - 1n−1).**

$s^2 = \frac1{n-1}\sum_i (X_i - \bar X)^2$ is an [unbiased estimator](#def-b1-sampling-and-inference-estimator) of $\sigma^2$.

**Proof.** $\sum_i (X_i - \bar X)^2 = \sum_i (X_i - \mu)^2 - n(\bar X - \mu)^2$. Taking expectations, $n\sigma^2 - n \cdot \sigma^2/n = (n - 1)\sigma^2$. ∎

```python
"""Dividing by n or by n - 1: the average of the sample variance, n = 5."""

import numpy as np
from econdata import nsw

y = nsw("psid_controls").re78.to_numpy()
rng = np.random.default_rng(2026)
samples = rng.choice(y, size=(200_000, 5))
print(f"population variance       {y.var() / 1e6:7.1f} million")
for ddof in (0, 1):
    v = samples.var(axis=1, ddof=ddof).mean()
    print(f"average, divided by n - {ddof} {v / 1e6:7.1f} million")
```

***Listing 31.1.** Dividing by $n$ or by $n - 1$, with samples of 5. code/bachelor-1/31-sampling-and-inference/listings/sample_variance.py*

```
$ python sample_variance.py
population variance         241.9 million
average, divided by n - 0   194.4 million
average, divided by n - 1   243.0 million
```

***Output 31.1.** Dividing by $n$ underestimates by the factor $4/5$.*

**Definition 31.5 (Mean squared error).**

The *mean squared error* of an [estimator](#def-b1-sampling-and-inference-estimator) is $\E[(\hat\theta - \theta)^2] = \text{bias}^2 + \Var(\hat\theta)$.

```python
"""Two estimators of mean earnings from samples of 10: bias, variance, MSE."""

import numpy as np
from econdata import nsw

y = nsw("psid_controls").re78.to_numpy()
mu = y.mean()
rng = np.random.default_rng(2026)
samples = rng.choice(y, size=(20_000, 10))
estimators = {
    "sample mean": samples.mean(axis=1),
    "0.8 x mean": 0.8 * samples.mean(axis=1),
}
print(f"population mean {mu:,.0f}")
for name, est in estimators.items():
    bias, var = est.mean() - mu, est.var()
    print(
        f"{name:12s} bias {bias:7,.0f}  sd {np.sqrt(var):6,.0f}"
        f"  root MSE {np.sqrt(bias**2 + var):6,.0f}"
    )
```

***Listing 31.2.** An [unbiased estimator](#def-b1-sampling-and-inference-estimator) and a shrunk one. code/bachelor-1/31-sampling-and-inference/listings/bias_variance.py*

```
$ python bias_variance.py
population mean 21,554
sample mean  bias      18  sd  4,917  root MSE  4,917
0.8 x mean   bias  -4,297  sd  3,934  root MSE  5,825
```

***Output 31.2.** Shrinking cuts the spread by a fifth but adds a bias of 4,297 dollars (of 1982, the unit of all the earnings in this chapter).*

Shrinking the mean towards zero trades bias for variance. Here the trade is bad — the root [mean squared error](#def-b1-sampling-and-inference-mse) rises from 4,917 to 5,825 dollars — because the mean is far from zero; for a parameter close to the point of shrinkage, it can be good. Several [estimators](#def-b1-sampling-and-inference-estimator) of the later volumes make this trade on purpose.

## 31.3 The standard error and confidence intervals

**Definition 31.6 (Standard error).**

The *standard error* of an [estimator](#def-b1-sampling-and-inference-estimator) is the standard deviation of its [sampling distribution](https://one-course.com/books/economics/3/en/chapter/30-random-variables-for-econometrics#def-b1-random-variables-for-econometrics-sampling-distribution); for the sample mean it is $\sigma/\sqrt n$, estimated by $\widehat{\mathrm{se}} = s/\sqrt n$.

**Definition 31.7 (Confidence interval).**

A *confidence interval* at level $1 - \alpha$ is an interval computed from the sample that contains the parameter in a share $1 - \alpha$ of repeated samples. For a mean, $\bar x \pm t_{n-1,\,1-\alpha/2}\,\widehat{\mathrm{se}}$, with $t_{n-1,\,1-\alpha/2}$ close to $1.96$ for $\alpha = 0.05$ and large $n$.

The level describes the procedure, not one interval: once computed, an interval contains the parameter or it does not.

```python
"""Mean 1978 earnings of the experiment's control group, with a 95% interval."""

import numpy as np
from econdata import nsw
from scipy import stats

y = nsw("nsw_dw").query("treat == 0").re78
n, mean, s = len(y), y.mean(), y.std()  # pandas divides by n - 1
se = s / np.sqrt(n)
c = stats.t.ppf(0.975, n - 1)
print(f"n {n}, mean {mean:,.0f}, s {s:,.0f}, standard error {se:,.0f}")
print(
    f"95% interval: {mean - c * se:,.0f} to {mean + c * se:,.0f} (t quantile {c:.3f})"
)
```

***Listing 31.3.** Mean earnings of the control group, with a 95% interval. code/bachelor-1/31-sampling-and-inference/listings/interval.py*

```
$ python interval.py
n 260, mean 4,555, s 5,484, standard error 340
95% interval: 3,885 to 5,224 (t quantile 1.969)
```

***Output 31.3.** From 3,885 to 5,224 dollars.*

```python
"""100 samples of 30 men, a 95% interval from each: how many miss the truth?"""

import numpy as np
from econdata import nsw
from scipy import stats


def intervals(reps=100, n=30, seed=2026):
    y = nsw("psid_controls").re78.to_numpy()
    rng = np.random.default_rng(seed)
    s = rng.choice(y, size=(reps, n))
    half = stats.t.ppf(0.975, n - 1) * s.std(axis=1, ddof=1) / np.sqrt(n)
    lo, hi = s.mean(axis=1) - half, s.mean(axis=1) + half
    return lo, hi, y.mean()


if __name__ == "__main__":
    lo, hi, mu = intervals()
    miss = (lo > mu) | (hi < mu)
    print(f"true mean {mu:,.0f}; intervals that miss it: {miss.sum()} of 100")
    print(
        "first misses:",
        [f"{a:,.0f}-{b:,.0f}" for a, b in zip(lo[miss][:3], hi[miss][:3])],
    )
```

***Listing 31.4.** One hundred intervals from one hundred samples of 30 men. code/bachelor-1/31-sampling-and-inference/listings/coverage.py*

```
$ python coverage.py
true mean 21,554; intervals that miss it: 10 of 100
first misses: ['11,767-20,207', '12,052-20,867', '22,399-34,092']
```

***Output 31.4.** Ten of the hundred miss.*

![One hundred 95\% intervals for mean earnings, each from 30 men drawn from the PSID sample; the population mean is dashed. The ten in red miss it.](https://one-course.com/images/onecourse/chapters/economics-3/b1-sampling-and-inference/fig-59532273c940.svg)

*One hundred $95\%$ intervals for mean earnings, each from 30 men drawn from the PSID sample; the [population](#def-b1-sampling-and-inference-population) mean is dashed. The ten in red miss it.*

Ten misses in a hundred is more than five, but one hundred intervals are a small sample of intervals: over 20,000 of them, $94.3\%$ contain the mean.

The shortfall from $95\%$ is real and comes from the [skewness](https://one-course.com/books/economics/3/en/chapter/29-describing-data#def-b1-describing-data-skewness) of earnings: with 30 draws, the $t$ interval is only approximately right.

## 31.4 Tests

**Definition 31.8 (Null hypothesis, alternative, test statistic).**

A test confronts a *null hypothesis* $H_0$ (say, $\mu_1 - \mu_0 = 0$) with an *alternative hypothesis* $H_1$ (say, $\mu_1 - \mu_0 \ne 0$). A *test statistic* is a function of the sample whose distribution under $H_0$ is known, at least approximately, such as $t = (\bar x_1 - \bar x_0)/\widehat{\mathrm{se}}$.

**Definition 31.9 (Significance level, ppp-value).**

A test rejects $H_0$ when the statistic falls in a rejection region. The *significance level*, or *size*, is the probability of rejecting $H_0$ when it is true. The *$p$-value* is the probability, computed under $H_0$, of a statistic at least as extreme as the one observed; a test at level $\alpha$ rejects when $p < \alpha$.

![A two-sided test at 5\%: the rejection regions beyond ± 1.96 (shaded), and the job-training experiment’s statistic.](https://one-course.com/images/onecourse/chapters/economics-3/b1-sampling-and-inference/fig-384e1c20147a.svg)

*A two-sided test at $5\%$: the rejection regions beyond $\pm 1.96$ (shaded), and the job-training experiment’s statistic.*

**On the record — What a ppp-value is not.**

In 2016 the American Statistical Association published six principles on $p$-values (Wasserstein and Lazar 2016). Two of them: a $p$-value does not measure the probability that the studied hypothesis is true, or the probability that the data were produced by random chance alone; and it does not measure the size of an effect or the importance of a result. A $p$-value of $0.008$ says that data this far from $H_0$ would be rare if $H_0$ held — not that $H_0$ has a $0.8\%$ chance of being true.

**Model — The randomised comparison.**

**Assumes.** People are assigned to a programme or to a control group at random, and one person’s assignment does not affect another’s outcome.

**Predicts.** The difference in mean outcomes estimates the programme’s average effect without bias, with the [standard error](#def-b1-sampling-and-inference-standard-error) of a difference of two means.

**Tested.** Two checks of the job-training experiment. Earnings before the programme, which assignment cannot have changed, are close in the two groups ($p = 0.98$ in 1974 and $0.39$ in 1975, [Output 31.5](#out-b1-sampling-and-inference-effect)), as random assignment predicts. And LaLonde (1986) used the experimental estimate as a benchmark that many non-experimental procedures failed to reproduce (record below).

**Breaks.** People who leave the study before the outcome is measured, in a way related to the treatment; samples so small that the interval is too wide to say anything; and effects that do not carry over to other people, places or scales, which the second university year takes up under causality and experiments.

```python
"""The experiment's estimate: treated against controls, 1978 earnings."""

import numpy as np
from econdata import nsw
from scipy import stats

d = nsw("nsw_dw")
t1, t0 = d.re78[d.treat == 1], d.re78[d.treat == 0]
diff = t1.mean() - t0.mean()
se = np.sqrt(t1.var() / len(t1) + t0.var() / len(t0))
t = diff / se
p_normal = 2 * stats.norm.sf(abs(t))
print(f"treated {len(t1)}, mean {t1.mean():,.0f}", end="; ")
print(f"controls {len(t0)}, mean {t0.mean():,.0f}")
print(f"difference {diff:,.1f}, standard error {se:,.1f}, t {t:.3f}")
print(f"p-value (normal) {p_normal:.4f}")
r = stats.ttest_ind(t1, t0, equal_var=False)
print(f"scipy (Welch):   t {r.statistic:.3f}, p-value {r.pvalue:.4f}")
print(f"95% interval: {diff - 1.96 * se:,.0f} to {diff + 1.96 * se:,.0f}")
for v in ("re74", "re75"):  # a check of the random assignment: earnings before
    a1, a0 = d[v][d.treat == 1], d[v][d.treat == 0]
    b = stats.ttest_ind(a1, a0, equal_var=False)
    print(f"{v}: treated {a1.mean():,.0f}, controls {a0.mean():,.0f}, p {b.pvalue:.2f}")
```

***Listing 31.5.** The experiment’s estimate, its [standard error](#def-b1-sampling-and-inference-standard-error), $t$ and $p$-value, and the earnings of the two groups before the programme. code/bachelor-1/31-sampling-and-inference/listings/nsw_effect.py*

```
$ python nsw_effect.py
treated 185, mean 6,349; controls 260, mean 4,555
difference 1,794.3, standard error 671.0, t 2.674
p-value (normal) 0.0075
scipy (Welch):   t 2.674, p-value 0.0079
95% interval: 479 to 3,109
re74: treated 2,096, controls 2,107, p 0.98
re75: treated 1,532, controls 1,267, p 0.39
```

***Output 31.5.** A difference of 1,794 dollars, $t = 2.67$, $p = 0.008$; before the programme, no difference.*

The [standard error](#def-b1-sampling-and-inference-standard-error) of a difference of two independent means is $\sqrt{s_1^2/n_1 + s_0^2/n_0}$, with $s_1$ and $s_0$ the standard deviations and $n_1$ and $n_0$ the sizes of the two groups. It lets each group keep its own variance, and the test built on it is *Welch’s test*. The pooled form, which assumes one common variance, would be wrong here: the treated men’s earnings in 1978 have a standard deviation of 7,867 dollars, the controls’ 5,484. The listing gives two $p$-values for the same $t$. The first uses the normal distribution, as the interval does with its $1.96$; Welch’s uses a Student $t$ with a degrees-of-freedom correction. With groups of 185 and 260 they agree: $0.0075$ and $0.0079$.

**On the record — The job-training experiment.**

A job-training programme in the United States assigned applicants at random to training or to a control group. The experiment gives an estimate that needs no model of who chooses to train. LaLonde (1986) replaced the experimental controls by comparison samples from two large surveys — the PSID and CPS samples of [Chapter 29](https://one-course.com/books/economics/3/en/chapter/29-describing-data#ch-b1-describing-data) — and found that many of the econometric procedures in use did not reproduce the experimental result. Dehejia and Wahba (1999) re-examined the samples with other methods.

The lesson: who is compared with whom matters more than the formula.

**Definition 31.10 (Power of a test).**

The *power* of a test against an alternative is the probability that it rejects $H_0$ when that alternative is true.

```python
"""Power to detect a 1,000-dollar effect with the experiment's sample sizes."""

import numpy as np
from econdata import nsw
from scipy import stats

d = nsw("nsw_dw")
y0 = d.re78[d.treat == 0].to_numpy()
n1, n0, effect = 185, 260, 1_000
se = np.sqrt(y0.var(ddof=1) * (1 / n1 + 1 / n0))  # one sd for both groups
power = stats.norm.sf(1.96 - effect / se) + stats.norm.cdf(-1.96 - effect / se)
print(f"standard error {se:,.0f}; power by the formula {power:.3f}")
rng = np.random.default_rng(2026)
reject = 0
for _ in range(4_000):  # draws from the control earnings, shifted by the effect
    a, b = rng.choice(y0, n1) + effect, rng.choice(y0, n0)
    reject += stats.ttest_ind(a, b, equal_var=False).pvalue < 0.05
print(f"power by simulation {reject / 4_000:.3f}")
```

***Listing 31.6.** [Power](#def-b1-sampling-and-inference-power) to detect an effect of 1,000 dollars with the experiment’s group sizes. code/bachelor-1/31-sampling-and-inference/listings/power.py*

```
$ python power.py
standard error 527; power by the formula 0.474
power by simulation 0.482
```

***Output 31.6.** Less than one chance in two.*

![Power of a two-sided 5\% test of a difference in mean earnings, with the control group’s standard deviation and two equal groups, for 100, 445 (the experiment’s size) and 2,000 people: an effect of 1,000 dollars is detected with probability 0.15, 0.49 and 0.98.](https://one-course.com/images/onecourse/chapters/economics-3/b1-sampling-and-inference/fig-52842bab3c9e.svg)

*[Power](#def-b1-sampling-and-inference-power) of a two-sided $5\%$ test of a difference in mean earnings, with the control group’s standard deviation and two equal groups, for 100, 445 (the experiment’s size) and 2,000 people: an effect of 1,000 dollars is detected with probability $0.15$, $0.49$ and $0.98$.*

## 31.5 Many tests at once

**Definition 31.11 (Family-wise error rate).**

The *family-wise error rate* of a set of tests is the probability that at least one of them rejects a true [null hypothesis](#def-b1-sampling-and-inference-test). Testing each of $m$ hypotheses at level $\alpha/m$ (the Bonferroni correction) keeps it at most $\alpha$.

The bound follows from $P(A_1 \cup \dots \cup A_m) \le \sum_j P(A_j) = m \cdot \alpha/m$. With 20 independent tests at $5\%$ and every null true, the chance of at least one rejection is $1 - 0.95^{20} = 64\%$.

```python
"""Twenty placebo tests: random halves of the PSID sample compared."""

import numpy as np
from econdata import nsw
from scipy import stats

y = nsw("psid_controls").re78.to_numpy()
rng = np.random.default_rng(7)
p = []
for _ in range(20):
    mask = rng.permutation(len(y)) < len(y) // 2  # a random half, no treatment at all
    p.append(stats.ttest_ind(y[mask], y[~mask], equal_var=False).pvalue)
p = np.array(p)
print("smallest p-values:", np.round(np.sort(p)[:3], 4))
print(f"rejections at 5%: {(p < 0.05).sum()} of 20; expected 1")
print(f"Bonferroni threshold 0.05/20 = {0.05 / 20}; rejections: {(p < 0.0025).sum()}")
```

***Listing 31.7.** Twenty tests where nothing is there. code/bachelor-1/31-sampling-and-inference/listings/many_tests.py*

```
$ python many_tests.py
smallest p-values: [0.0397 0.0581 0.0795]
rejections at 5%: 1 of 20; expected 1
Bonferroni threshold 0.05/20 = 0.0025; rejections: 0
```

***Output 31.7.** One “significant” difference between two random halves of the same men.*

The seed, 7, was chosen to show a typical draw, with the one rejection that twenty tests at $5\%$ give on average; of the seeds 0 to 99, 40 give no rejection, 38 one and 22 two or more. A study that runs twenty comparisons and reports the one with $p = 0.04$ has shown nothing. The third university year returns to the search for specifications and how credible work guards against it.

## 31.6 Survey design and weights

**Definition 31.12 (Stratified sample, sampling weight, design effect).**

A *stratified sample* divides the [population](#def-b1-sampling-and-inference-population) into groups (strata) and draws a separate [random sample](https://one-course.com/books/economics/3/en/chapter/30-random-variables-for-econometrics#def-b1-random-variables-for-econometrics-random-sample) in each. A unit’s *sampling weight* is the inverse of its probability of being drawn: the number of [population](#def-b1-sampling-and-inference-population) units it stands for. The *design effect* is the variance of an estimate under the design divided by its variance under a simple [random sample](https://one-course.com/books/economics/3/en/chapter/30-random-variables-for-econometrics#def-b1-random-variables-for-econometrics-random-sample) of the same size.

```python
"""A stratified sample of Brenland households: owners over-sampled."""

import numpy as np
import pandas as pd
from country import load

h = load("households")
rng = np.random.default_rng(2026)
take = {1: 150, 0: 150}  # 150 owners and 150 renters
parts = [h[h.owner == k].sample(m, random_state=rng) for k, m in take.items()]
sample = pd.concat(parts)
N = h.owner.value_counts()  # households in each stratum
sample["weight"] = sample.owner.map(N) / sample.owner.map(take)  # 1 / P(drawn)
y, w = sample.disposable, sample.weight
print(f"true mean {h.disposable.mean():,.0f}")
print(f"unweighted {y.mean():,.0f}; weighted {(w * y).sum() / w.sum():,.0f}")
print("weights:", sample.groupby("owner").weight.first().round(2).to_dict())
deff = 1 + (w.std(ddof=0) / w.mean()) ** 2  # Kish's design effect of weighting
print(f"design effect {deff:.3f}; effective sample size {len(sample) / deff:.0f}")
```

***Listing 31.8.** Owners over-sampled, then weighted back. code/bachelor-1/31-sampling-and-inference/listings/weights.py*

```
$ python weights.py
true mean 24,920
unweighted 26,475; weighted 24,822
weights: {0: 9.12, 1: 4.21}
design effect 1.135; effective sample size 264
```

***Output 31.8.** Unweighted, the sample overstates income by 1,555 dalens; weighted, it is 98 dalens off.*

Owners are a third of households but half the sample, and they have higher incomes, so the unweighted mean is too high. Unequal weights cost precision: the [design effect](#def-b1-sampling-and-inference-weights) of $1.135$ makes 300 households worth 264 drawn at random. (The formula $1 + \mathrm{CV}^2$ of the weights is Kish’s approximation for weighting alone; stratification itself usually lowers the variance.)

**How it is measured — The monthly unemployment survey.**

A labour-force survey asks a sample of households about each member’s work and job search in a reference week, and classifies each person as employed, unemployed or out of the labour force. The rate is the weighted number of unemployed divided by the weighted labour force. A $90\%$ interval spans about $1.6$ [standard errors](#def-b1-sampling-and-inference-standard-error) on each side; for the US monthly change, it is about $\pm 0.3$ point at a rate around $6\%$. Households stay in the sample for several months, so successive samples overlap, which makes the [standard error](#def-b1-sampling-and-inference-standard-error) of a change smaller than that of two independent samples.

```python
"""A monthly survey of 100,000 people in the labour force, true rate 6.0%."""

import numpy as np

rng = np.random.default_rng(2026)
n, rate = 100_000, 0.060
months = rng.binomial(n, rate, size=2) / n  # two independent monthly samples
se = np.sqrt(rate * (1 - rate) / n)
print(
    f"estimates {100 * months[0]:.2f}% and {100 * months[1]:.2f}%; standard error"
    f" {100 * se:.3f} points"
)
change = months[1] - months[0]
se_change = np.sqrt(2) * se  # independent samples; overlapping samples do better
print(
    f"change {100 * change:+.2f} points; its standard error {100 * se_change:.3f};"
    f" 90% margin {100 * 1.645 * se_change:.2f}"
)
```

***Listing 31.9.** A simulated monthly survey and the change between two months. code/bachelor-1/31-sampling-and-inference/listings/unemployment_survey.py*

```
$ python unemployment_survey.py
estimates 5.94% and 6.04%; standard error 0.075 points
change +0.10 points; its standard error 0.106; 90% margin 0.17
```

***Output 31.9.** A change of $0.10$ point when nothing changed.*

## Exercises

**Exercise 31.1 ★.**

A sample of 400 has a standard deviation of 9,000. Find the [standard error](#def-b1-sampling-and-inference-standard-error) of its mean.

**Solution of Exercise 31.1.**

$9{,}000/\sqrt{400} = 450$.

**Exercise 31.2 ★.**

From [Output 31.5](#out-b1-sampling-and-inference-effect), give the estimated effect, its [standard error](#def-b1-sampling-and-inference-standard-error) and the $p$-value of Welch’s test.

**Solution of Exercise 31.2.**

1,794.3 dollars, with a [standard error](#def-b1-sampling-and-inference-standard-error) of 671.0; Welch’s test gives $p = 0.0079$.

**Exercise 31.3 ★.**

A test gives $p = 0.03$. Which statement is right? (a) $H_0$ has a $3\%$ chance of being true. (b) The effect is large. (c) If $H_0$ were true, a statistic at least this extreme would occur in $3\%$ of samples. (d) The result has a $97\%$ chance of being replicated.

**Solution of Exercise 31.3.**

(c). A $p$-value is computed assuming $H_0$, so it is not the probability of $H_0$ (a); it does not measure the size of the effect (b); and it is not a probability of replication (d).

**Exercise 31.4 ★.**

Predict the width of a $95\%$ interval when the sample size is multiplied by 4.

**Solution of Exercise 31.4.**

The [standard error](#def-b1-sampling-and-inference-standard-error) is divided by $\sqrt4 = 2$, so the width halves.

**Exercise 31.5 ★★.**

Find the bias of $\tilde\mu = \frac1{n+1}\sum_{i=1}^n X_i$ as an [estimator](#def-b1-sampling-and-inference-estimator) of $\mu$. Is it consistent?

**Solution of Exercise 31.5.**

$\E[\tilde\mu] = n\mu/(n+1)$, a bias of $-\mu/(n+1)$. It is consistent: $\tilde\mu = \frac{n}{n+1}\bar X_n$, the factor tends to 1 and $\bar X_n$ is consistent.

**Exercise 31.6 ★★.**

In two [random samples](https://one-course.com/books/economics/3/en/chapter/30-random-variables-for-econometrics#def-b1-random-variables-for-econometrics-random-sample) of 400, 120 and 90 people say they are looking for another job. Test at $5\%$ whether the two [population](#def-b1-sampling-and-inference-population) shares differ.

**Solution of Exercise 31.6.**

$\hat p_1 = 0.300$, $\hat p_2 = 0.225$, pooled $\hat p = 210/800 = 0.2625$. The [standard error](#def-b1-sampling-and-inference-standard-error) under $H_0$ is $\sqrt{0.2625 \times 0.7375 \times 2/400} = 0.0311$, so $z = 0.075/0.0311 = 2.411$ and $p = 0.0159$: the shares differ at $5\%$.

**Exercise 31.7 ★★.**

With the standard deviations of the experiment’s two groups (7,867 and 5,484 dollars), how many people per group give a [power](#def-b1-sampling-and-inference-power) of $80\%$ to detect an effect of 1,000 dollars at $5\%$, two-sided?

**Solution of Exercise 31.7.**

[Power](#def-b1-sampling-and-inference-power) $80\%$ at $5\%$ two-sided needs a [standard error](#def-b1-sampling-and-inference-standard-error) of $1{,}000/(1.960 + 0.842) = 1{,}000/2.8016 = 357$ dollars. With $m$ people per group, $\sqrt{(7{,}867^2 + 5{,}484^2)/m} = 357$ gives $m = 722$: 1,444 people in all, more than three times the experiment’s 445.

**Exercise 31.8 ★★.**

Fifty true null hypotheses are tested at $5\%$. How many rejections do you expect? What is the Bonferroni threshold?

**Solution of Exercise 31.8.**

$50 \times 0.05 = 2.5$ rejections on average; the Bonferroni threshold is $0.05/50 = 0.001$.

**Exercise 31.9 ★★.**

A survey over-samples young households, whose income is lower than average. Predict which of the weighted and unweighted mean incomes is closer to the [population](#def-b1-sampling-and-inference-population)’s, and why.

**Solution of Exercise 31.9.**

The weighted mean: young households are over-represented in the sample, so the unweighted mean is pulled down; the weights give each household the share of the [population](#def-b1-sampling-and-inference-population) it stands for.

**Exercise 31.10 ★★★.**

Write out the proof of [Proposition 31.4](#prop-b1-sampling-and-inference-variance), justifying the decomposition of $\sum_i (X_i - \bar X)^2$ and each expectation.

**Solution of Exercise 31.10.**

Write $X_i - \bar X = (X_i - \mu) - (\bar X - \mu)$. Squaring and summing, the cross term is $-2(\bar X - \mu)\sum_i (X_i - \mu) = -2n(\bar X - \mu)^2$, so $\sum_i (X_i - \bar X)^2 = \sum_i (X_i - \mu)^2 - n(\bar X - \mu)^2$. Each $\E[(X_i - \mu)^2] = \sigma^2$, and $\E[(\bar X - \mu)^2] = \Var(\bar X) = \sigma^2/n$ by independence. The expectation is $n\sigma^2 - \sigma^2 = (n - 1)\sigma^2$; dividing by $n - 1$ gives $\sigma^2$.

**Exercise 31.11 ★★★.**

Show that an [estimator](#def-b1-sampling-and-inference-estimator) can be biased and consistent, with an example from this chapter.

**Solution of Exercise 31.11.**

The variance divided by $n$, $\hat\sigma^2 = \frac{n-1}{n}s^2$, has expectation $\frac{n-1}{n}\sigma^2$: biased, as [Output 31.1](#out-b1-sampling-and-inference-variance) shows for $n = 5$. Its bias $-\sigma^2/n$ tends to zero and its variance too (when the fourth moment is finite), so it is consistent. The [estimator](#def-b1-sampling-and-inference-estimator) $\tilde\mu$ of [Exercise 31.5](#exo-b1-sampling-and-inference-bias) is another example.

**Exercise 31.12 ★★★.**

What pattern among published $p$-values would show that many tests were run and only the significant ones reported?

**Solution of Exercise 31.12.**

Too many $p$-values just below $0.05$ and too few just above it, compared with the smooth distribution that honest reporting of all tests would give; and too few studies with insignificant results.

## 31.7 Problem: The Brenland Labour-Force Survey

**Problem 31.1.**

Weekend problem — how big must the survey be?

Brenland (invented) has three regions: the Capital (2.0 million in the labour force, true unemployment rate $5.0\%$), the North (1.5 million, $6.5\%$) and the South (1.0 million, $7.25\%$). Each month the statistical office samples 4,000 people in the labour force of each region, independently from month to month. In month 2 every regional rate rises by $0.2$ point. A script simulates the two months; its seed, 2028, was chosen to show a typical draw, one whose measured change is within half a [standard error](#def-b1-sampling-and-inference-standard-error) of the true one.

**Part I — Design.**

1. Give each region’s share of the labour force and the true national rate.
2. Give each region’s probability of selection.
3. Give the [sampling weights](#def-b1-sampling-and-inference-weights) .
4. Why sample the same number in each region?
5. Which way would an unweighted rate be biased?
6. Give the [design effect](#def-b1-sampling-and-inference-weights) of the weights by Kish’s formula.

**Part II — The estimate.**

7. Give the unemployed counted in each region’s sample in month 1.
8. Give the regional rates and their [standard errors](#def-b1-sampling-and-inference-standard-error) .
9. Give the unweighted national rate.
10. Give the weighted national rate.
11. Give its [standard error](#def-b1-sampling-and-inference-standard-error) , $\sqrt{\sum_h W_h^2\,\hat p_h(1 - \hat p_h)/n_h}$ , with $W_h$ the regions’ shares.
12. Compare with the [standard error](#def-b1-sampling-and-inference-standard-error) of a simple [random sample](https://one-course.com/books/economics/3/en/chapter/30-random-variables-for-econometrics#def-b1-random-variables-for-econometrics-random-sample) of 12,000.
13. Give a $95\%$ interval.

**Part III — The change.**

14. Give the weighted rate in month 2.
15. Give the change.
16. Give the [standard error](#def-b1-sampling-and-inference-standard-error) of the change.
17. Give the $t$ statistic and the $p$ -value.
18. Does the survey detect the rise at $5\%$ ?
19. Is the drawn change far from the true one?
20. How would keeping the same people in the sample from one month to the next change the [standard error](#def-b1-sampling-and-inference-standard-error) of the change?

**Part IV — The sample size.**

21. What [standard error](#def-b1-sampling-and-inference-standard-error) of the change gives a [power](#def-b1-sampling-and-inference-power) of $80\%$ to detect a $0.2$ -point rise at $5\%$ , two-sided?
22. Give the [standard error](#def-b1-sampling-and-inference-standard-error) of the change with 12,000 people, from the true rates.
23. How many people a month, with the same design, give the [power](#def-b1-sampling-and-inference-power) of item 21?
24. And with a simple [random sample](https://one-course.com/books/economics/3/en/chapter/30-random-variables-for-econometrics#def-b1-random-variables-for-econometrics-random-sample) ?
25. How many with overlapping samples whose estimates have a correlation of $0.5$ between months?
26. State the result.

**Solution of Problem 31.1.**

**1.** Shares $0.444$, $0.333$, $0.222$; true rate $0.444 \times 5.0 + 0.333 \times 6.5 + 0.222 \times 7.25 = 6.0\%$.

**2.** $4{,}000/2{,}000{,}000 = 0.0020$; $0.00267$; $0.0040$.

**3.** 500, 375 and 250 people each.

**4.** To estimate each region’s rate with the same precision, the small regions included.

**5.** Upwards: the South, with the highest rate, is over-represented.

**6.** $1.074$.

**7.** 201, 272 and 298.

**8.** $5.03\%$, $6.80\%$ and $7.45\%$, with [standard errors](#def-b1-sampling-and-inference-standard-error) $0.345$, $0.398$ and $0.415$ point.

**9.** $771/12{,}000 = 6.425\%$.

**10.** $6.156\%$.

**11.** $0.223$ point.

**12.** $0.219$ point: the design is slightly less precise for the national rate, as the [design effect](#def-b1-sampling-and-inference-weights) predicts.

**13.** $5.72\%$ to $6.59\%$.

**14.** $6.456\%$.

**15.** $+0.300$ point.

**16.** $\sqrt{0.2229^2 + 0.2283^2} = 0.319$ point.

**17.** $t = 0.941$, $p = 0.347$.

**18.** No.

**19.** No: $0.1$ point from the true $0.2$, a third of a [standard error](#def-b1-sampling-and-inference-standard-error).

**20.** With a correlation $\rho$ between the two months’ estimates, the variance of the change is multiplied by $1 - \rho$: overlap makes changes more precise.

**21.** $0.2/(1.960 + 0.842) = 0.0714$ point.

**22.** $0.312$ point.

**23.** $12{,}000 \times (0.3119/0.0714)^2 \approx 229{,}000$ people a month.

**24.** $2 \times 0.06 \times 0.94/0.000714^2 \approx 221{,}000$.

**25.** Half as many: about 115,000.

**26.** To detect a $0.2$-point monthly change with $80\%$ [power](#def-b1-sampling-and-inference-power), Brenland’s survey needs about 229,000 people a month, not 12,000 — about 115,000 if the samples overlap enough for a correlation of $0.5$.
