Finding moment generating function of $f(x)= \frac 1 {\theta^2} xe^{-x/\theta}$ I've been stuck on this question for a while now and my exam is coming up so,any hints/comments etc. would be greatly appreciated.
Question: 
Find the moment generating function of the probability density function with parameter $\theta > 0$, 
$$f(x)= \frac 1 {\theta^2} xe^{-x/\theta}$$
I've tried the Gamma function and Integration by Parts but I'm still stuck.
The answer key gives this answer (I've attached a photo), but I'm not sure how they got to last step...
Thanks so much. 
 A: First let's write $x= \theta y$ to save digital trees,
$$ \int_0^{\infty} e^{xt} \frac{1}{\theta^2}xe^{-x/\theta} \, dx = \int_0^\infty e^{\theta t y}ye^{-y} \, dy = \int_0^{\infty} y e^{-(1-t\theta)y} \, dy. $$
Now we do the integration by parts: we have
$$ \int_0^{\infty} y e^{-ay} \, dy = \left[ -\frac{1}{a}ye^{-ay} \right]_0^{\infty}+\frac{1}{a}\int_0^{\infty} e^{-ay} \, dy. $$
The first term evaluates to $0$ (easy enough to see), and the second can be integrated directly to give
$$ \int_0^{\infty} y e^{-ay} \, dy = \frac{1}{a^2}. $$
Now, in our case $a=(1-\theta t)$, which gives you your answer.
A: It's unclear which part you're not sure about.  Several things were done:


*

*First $\displaystyle\operatorname{E}(e^{tX})$ is seen to be equal to $\displaystyle \int_0^\infty e^{tx} f(x)\,dx$.

*Then $f(x)$ is replaced by $\dfrac 1 {\theta^2} x e^{-x/\theta}$, so the integral becomes $\displaystyle\int_0^\infty e^{tx} \frac 1 {\theta^2} x e^{-x/\theta} \, dx$.

*The constant $1/\theta^2$ is pulled out, so you get $\displaystyle\frac 1 {\theta^2} \int_0^\infty e^{tx} x e^{-x/\theta}\,dx$.  That can be done because $1/\theta^2$ does not change as $x$ goes from $0$ to $\infty$.

*Then $e^{tx} e^{-x/\theta}$ becomes $e^{tx-x/\theta}$, and $tx-x/\theta$ is the same as $-\left(\frac 1 \theta - t\right)x$.

*Then there is the problem of evaluating $\displaystyle\int_0^\infty x e^{-(\frac 1 \theta - t)x} \, dx$.  You have $$\int_0^\infty x e^{-ax} \, dx = \frac 1 {a^2} \int_0^\infty (ax) e^{-ax}\left(a\,dx\right) = \frac 1 {a^2} \int_0^\infty u e^{-u}\,du.$$

*Then there is the fact that $\displaystyle\int_0^\infty u e^{-u}\,du=1$.  You can do that by integrating by parts.
More specificity about which step you are unsure of would improve the question.
A: If you recognize that the integral of a gamma density is $1$ over its support; i.e., you accept that $$\int_{x=0}^\infty \frac{x^{\alpha-1} e^{-x/\beta}}{\Gamma(\alpha) \beta^\alpha} \, dx  = 1,$$ then it is easy to compute the MGF:  consider $$\begin{align*} M_X(t) = \operatorname{E}[e^{tX}] &= \int_{x=0}^\infty e^{tx} \frac{x^{\alpha-1} e^{-x/\beta}}{\Gamma(\alpha) \beta^\alpha} \, dx \\ &= \frac{1}{\beta^\alpha} \int_{x=0}^\infty \frac{x^{\alpha-1}}{\Gamma(\alpha)} e^{-x(1/\beta - t)} \, dx ,\end{align*}$$ where I have moved the constant factor $\beta^\alpha$ out of the integral, and I have combined $$e^{tx} e^{-x/\beta} = e^{tx - x/\beta} = e^{x(t-1/\beta)} = e^{-x(1/\beta - t)}.$$  Now this suggests defining $$\frac{1}{\beta^*} = \frac{1}{\beta} - t,$$ so that now we write $$M_X(t) = \frac{1}{\beta^\alpha} \int_{x=0}^\infty \frac{x^{\alpha-1}}{\Gamma(\alpha)} e^{-x/\beta^*} \, dx.$$  Now the integral in this expression would be equal to $1$ if we could divide the integrand by $(\beta^*)^\alpha$, since then the integrand would be the density of a gamma distribution with shape parameter $\alpha$ and scale parameter $\beta^*$ (rather than the original density with started with, which had shape $\alpha$ but scale $\beta$).  So we just put it in there:  $$M_X(t) = \frac{(\beta^*)^\alpha}{\beta^\alpha} \int_{x=0}^\infty \frac{x^{\alpha-1} e^{-x/\beta^*}}{\Gamma(\alpha) (\beta^*)^\alpha} \, dx = \left( \frac{\beta^*}{\beta} \right)^\alpha .$$  Now all that is left is to rewrite the MGF explicitly in terms of $t$.  Note we use a little trick at the beginning:  $$M_X(t) = \left(\beta \cdot \frac{1}{\beta^*}\right)^{-\alpha} = \left( \beta \left( \frac{1}{\beta} - t \right) \right)^{-\alpha} = (1 - \beta t)^{-\alpha},$$ and we are mostly done.  All that remains is to observe that we require $\beta^* > 0$; equivalently, that $t < 1/\beta$.  Otherwise, the integral doesn't converge.
So, how does this apply to your question?  Your density is simply a gamma distribution for $\alpha = 2$ and $\beta = \theta$.  So the MGF is $$M_X(t) = (1 - \theta t)^{-2}, \quad t < 1/\theta.$$  Notice also that the solution that you were provided goes along the exact same lines as what I wrote in the general case, although it is not so detailed as mine.  Of course, I started from the assumption that the integral of a gamma density is $1$.  A proof of this fact is not difficult, as it is really more related to the fact that the gamma function itself is defined as $$\Gamma(\alpha) = \int_{x=0}^\infty x^{\alpha-1} e^{-x} \, dx,$$ hence  an appropriate variable substitution will establish this fact.
