A random variable, $X$, has a value of zero with probability $1/3$, and follows a uniform distribution over $[-1, 1]$ with probability $2/3$. How can I derive the pdf of $X$?
In my opinion, $X$ can be formulated as $$X=\cases{0, &if $Y \le 1,$\\Z, &if $Y>1$,}$$ where $Y$ is a random variable uniformly distributed over $[0,3]$ and $Z$ is a random variable uniformly distributed over $[-1, 1]$.
If the conditions (e.g., $Y\le1$ and $Y >1$) are defined in terms of $X$ (e.g., $X\le1$ and $X>1$), the pdf of $X$ may be obtained by finding the cdf of $X$ and differentiating it. However, $Y$ makes me crazy. How can I find the pdf of $X$? Actually, my final goal is to find $\mathbb{E}\left[-\log_2 f_X(x) \right]$, where $f_X(x)$ denotes the pdf of $X$.
Finding the cdf is the best route forward. For a uniform distribution on $[-1,1]$, the cdf is $\frac{1}{2}(x+1)$ for $x \in [-1,1]$ With a probability of 1/3 at 0, you have to split it up to 3 cases, where x is negative, 0, and positive. x has a 1/3 probability of being negative, with a uniform distribution, indicating that the cdf is $\frac{1}{3}(x+1)$ on $[-1,0)$. For $x=0$ the cdf will equal $\frac{2}{3}$. For $x>0$, the cdf will equal $\frac{2}{3}+\frac{1}{3}x$. To find the pdf, you can differentiae, but you will not get a finite value at $x=0$, which is to be expected for a discrete mass point. For a pdf, it is sometimes written with a delta function.