Problem calculating joint and marginal distribution of two uniform distributions Suppose we have random variable $X_1$ distributed as $U[0,1]$ and $X_2$ distributed as  $U[0,X_1]$, where $U[a,b]$ means uniform distribution in interval $[a,b]$.
I was able to compute joint pdf of $(X_1,X_2)$ and marginal pdf of $X_1$.
$$ p(x_1,x_2) = \frac{1}{x_1}, \text{ for }\quad 0\le x_1\le 1, \quad 0\le x_2 \le x_1,$$
$$ p(x_1)= 1, \text{ for } \quad 0\le x_1\le 1.$$
However while computing marginal pdf of $X_2$ I am encountering limits problem. The resultant of integral through marginal of $X_2$ is $\log(X_1)$ and the limits are from 0 to 1. As $\log(X_1)$ is not defined for $X_1=0$, I am facing a difficulty.
Am I wrong somwhere? Thanks.
 A: In the "marginalisation" integral, the lower limit for $x_1$ is not $0$ but $x_2$ (because of the $0<x_2<x_1$ condition).
So the integral should be:
$$p(x_2)=\int p(x_1,x_2) dx_1=\int \frac{I(0\leq x_2\leq x_1\leq 1)}{x_1} dx_1=\int_{x_2}^{1} \frac{dx_1}{x_1}=log\big(\frac{1}{x_2}\big)$$
You have stumbled across, what I think is one of the hardest parts of statistical integrals - determining the limits of integration.
NOTE: This is consistent with Henry's answer, mine is the PDF, and his is the CDF.  Differentiating his answer gives you mine, which shows we are both right.
A: You should not have $X_1$ in the marginal distribution for $X_2$
I would expect you to get $P(X_2 \le x_2) = x_2 (1-\log(x_2))$ and so the derivative gives a marginal density of $-\log(x_2)$.  
This comes from $P(X_2 \le x_2 |X_1=x_1) = 1$ if $x_1 \le x_2$, and $ P(X_2 \le x_2 |X_1=x_1) = \frac{x_2}{x_1}$ if $x_2 \le x_1$ so the integral is 
$$P(X_2 \le x_2) = \int_{x_1=0}^{x_2} dx_1 + \int_{x_1=x_2}^{1} \frac{x_2}{x_1} dx_1$$ 
$$ = \left[ x_1 \right]_{x_1=0}^{x_1=x_2} + \left[x_2 \log(x_1)\right]_{x_1=x_2}^{x_1=1} $$
$$ = x_2 - 0 +x_2 \log(1) - x_2 \log(x_2) $$
$$ = x_2 (1-\log(x_2))$$ 
