Expected value problem: a couple stops having children as soon as they have a child that has the same gender as their first Givens:


*

*$p$ is a real number with $0 < p < 1$

*Child is a boy with probability $p$

*Child is a girl with probability $1-p$

*Anna and Ben stop having children as soon as they have a child that has the same gender as their first child.

*Random variable $X$= number of children that Anna and Ben have


Required: $E(X)$.
I know that I need to use the fact that $\sum_{k=1}^{\infty} k x^{k-1} = 1/(1-x)^2$ but I don't know how.
Could someone please explain/show how answer this question?

Case 1: Getting at first a boy and at last a boy
The probabiltiy to get  first a boy and at last a boy in n attempts is
$p \cdot (1-p)^{n-2}\cdot p$ 
The expected value is $\sum_{n=2}^{\infty } n\cdot p^2 \cdot (1-p)^{n-2}$
Now you can make an index shift: $k=n-1 \Rightarrow n=k+1$
$\sum_{k=1}^{\infty} (k+1) \cdot p^2 \cdot (1-p)^{k-1}$
$=\sum_{k=1}^{\infty} 1 \cdot p^2 \cdot (1-p)^{k-1}+\sum_{k=1}^{\infty} k \cdot p^2 \cdot (1-p)^{k-1}$
factor out $p$ and $p^2$
$=p\sum_{k=1}^{\infty} 1 \cdot p \cdot (1-p)^{k-1}+p^2\sum_{k=1}^{\infty} k \cdot (1-p)^{k-1}$


*

*$\sum_{k=1}^{\infty} 1 \cdot p \cdot (1-p)^{k-1}=1$

*And from your formula you know, that $\sum_{k=1}^{\infty} k \cdot
   (1-p)^{k-1}=\frac{1}{(1-(1-p))^2}=\frac{1}{p^2}$


Thus we get $p+\frac{p^2}{p^2}=p+1$
Case 2: Getting at first a girl and at last a girl
The expected value is $\sum_{n=2}^{\infty } n\cdot (1-p)^2 \cdot p^{n-2}$
The further calculations are similar. The result, in this case, is $2-p$.
