# Random variable conditioned to gamma distribution

Suppose that we have two random variable $X$ and $Y$, where $X$ ~ $Gamma (2,1)$ and that $Y|X$ ~ $U(0,x)$. Find the distribution of Y.

The way I approach it as follows:

We know that $f_X(x) = xe^{-x}$ for $x\in(0,\infty)$ and that $f_{Y|X}(y|x) = 1/x$ for $y\in(0,x)$.

To find the distribution we integrate: $$f_Y(y) =\int_0^{\infty} f(x,y)dx = \int_0^{\infty} f_{Y|X}(y|x)f(x)dx = \int_0^{\infty} e^{-x}dx = 1$$

What distribution is this, since $y$ has the support $(0, \infty)$? Am I doing anything wrong?

Note that $$f_{Y \mid X}(y \mid x) = \frac{1}{x}$$ if and only if $y \in (0,x)$. So if you integrate, you must take into account this restriction in the relationship between $X$ and $Y$. Specifically, $$f_Y(y) = \int_{x=0}^\infty f_{Y \mid X}(y \mid x) f_X(x) \, dx = \int_{x=y}^\infty \frac{1}{x} \cdot xe^{-x} \, dx = e^{-y}, \quad y > 0.$$ This is because, for a given fixed $y$, the aforementioned conditional density $f_{Y \mid X}$ is zero if $x < y$; therefore, the lower limit of integration must begin at $x = y$, not $x = 0$.