
I am working on this problem, where I am required to write down the pgf of $X$, as well as the pgf of $Y$ given $X=j$, and then using conditional expectation find the pgf of $Z$.
So far, I have \begin{align*} G_{X}(z)&=(pz+(1-p))^{n}\\ G_{Y|X=j}(z)&=(qz+(1-q))^{n+j} \end{align*}
I'm new to generating functions and am having difficulty finding the pgf of $Z$. I thought I had a breakthrough when I wrote down \begin{align*} G_{Z}(z)&=\mathbb{E}\left(z^{Z}\right)\\ &=\mathbb{E}\left(z^{n+j-Y}\right)\\ &=\frac{z^{n+j}}{G_{Y}(z)} \end{align*}
But I'm quite sure this isn't correct as I am then required to deduce that $Z$ has the same distribution as the sum of two independent Binomial random variables. I don't know how to apply conditional expectation here. I'm sure this is a very simple problem, and I just want to understand it. Thanks for your patience and time.
Use the definition of a probability generating function and the Law of Iterated Expectation:
$\begin{align} G_Y(z) & = \mathsf E(\mathsf E(z^Y\mid X)) \\ & = \mathsf E(G_{Y\mid X}(z)) \\ & = \mathsf E((qz+1-q)^{n+X}) \\ & = (qz+1-q)^n\mathsf E((qz+1-q)^{X}) \\ & = (qz+1-q)^n G_{X}(qz+1-q) \\ & = (qz+1-q)^n \cdot\big(p(qz+1-q)+1-p\big)^n \\ & = (qz+1-q)^n \cdot\big(pqz+1-pq\big)^n \end{align}$
Similarly you can obtain the pgf of $Z$ by:
$\begin{align} G_Z(z) & = \mathsf E(z^{n+X-Y}) \\ & = z^n\mathsf E(z^X\;\mathsf E((\tfrac 1z)^Y\mid X)) \\ & = z^n\mathsf E(z^X\;G_{Y\mid X}(\tfrac 1z)) \\ & = z^n\mathsf E(z^X\;(qz^{-1}+1-q)^{n+X})) \\ & = (q+(1-q)z)^n\;\mathsf E((q+(1-q)z)^{X}) \\ & = (q+(1-q)z)^n\;G_X(q+(1-q)z) \\ & = (q+(1-q)z)^n\;(p(q+(1-q)z)+1-p)^n \\ & = (q+(1-q)z)^n\;(p(1-q)z+1-p(1-q))^n \\ & = (qp(1-q)z+q-pq(1-q)+p(1-q)^2z^2+(1-q)z-p(1-q)^2z)^n \\ & = (p q^2 -2 p q +p )z^2+(-2 p q^2+3 p q-p -q +1)z+(p q^2-p q+q) \end{align}$