Expected value of a mean when previous values determine stopping point I recently came across this brain teaser:

There's an island and every family on the island wants to have a boy.
  So each family continues having kids until they have a boy, then they
  stop having kids. What's the ratio of boys to girls on this island?

I worked out the answer (the math required isn't really the topic of this question) and found that the ratio of boys to girls on the island is 1:1. Then I realized that I think it's 1:1 no matter what criteria families use to decide when to stop having kids.
In discussions with friends the above seemed counter-intuitive to some. So slightly more formally (and apologies if this isn't formal enough, it's been a while since I've studied this):

We are going to sample a random variable some (possibly infinite) number of times and consider the sum of these values. Is it true that looking at previous values to decide when to stop sampling cannot alter the expected value of the mean? The values of each sample are independent and identically distributed.

 A: Let $(X_j)_{j \in \mathbb{N}}$ be a sequence of independent random variables such that $\mathbb{P}(X_j = 1) = \mathbb{P}(X_j =-1) = \frac{1}{2}$. The event $\{X_j = 1\}$ models that the $j$-th child is a boy, $\{X_j = -1\}$ models the event that it is a girl. Then
$$S_n := \sum_{j=1}^n X_j$$
describes how much more boys are born than girls until the $n$-th child. So, if $S_n = 0$, then the ratio of boys and girls is 1:1.  Clearly, we have
$$\mathbb{E}(S_n)=0,$$
i.e. we expect that we have as many girls as boys. If we define a random variable $\tau$ by
$$\tau := \inf\{n \geq 1; X_n = 1\},$$
then the $\tau$-th child is exactly the first boy to a family. It follows from martingale theory (more precisely, the optional stopping theorem), that
$$\mathbb{E}(S_{\tau})=0 \tag{1}$$
which means that the expected value of the ratio is 1:1 if the families stop having children as described in the question. $(1)$ does not only hold for this particular random variable $\tau$ but for more general ones; the important properties of $\tau$ are


*

*the event $\{\tau=n\}$ does only depend on the first $n$ children of a family, i.e. the stopping does not depend on the future.

*some integrability condition, e.g. $\mathbb{E}(\tau)<\infty$ (this condition is not necessary, but sufficient).


To see that the first property is not enough, consider the following stopping strategy.

A family stops having kids if the fmaily has (strictly) more boys than girls.

This translates to $\tau := \inf\{S_n \geq 1\}$. Obviously, we cannot expect that the expected value of the ration is $1:1$ if the families use this strategy, in particular. the equality $\mathbb{E}(S_{\tau})=0$ does not hold. One might wonder whether this strategy is admissible, i.e.
$$\mathbb{P}(\tau<\infty)=1,$$
which means intuitively that each family ends up with finitely many children. However, is is possible that this does indeed hold true (although $\mathbb{E}\tau=\infty$).
