Example 2 How many four-digit numbers have the sum of their digits equal to 12?
Let the number of four-digit numbers with the sum of digits being $n$ be $a_{n}$, then $a_{n}=\sum_{t_{1}+t_{2}+t_{3}+t_{4}=n} 1\left(t_{i}\right.$ are non-negative integers, $i=1,2,3,4), 1 \leqslant t_{1} \leqslant 9,0 \leqslant t_{j} \leqslant 9(j=2,3,4)$, then the generating function for $a_{n}$ is
$$
\begin{aligned}
f(x) & =\sum_{n=0}^{\infty} a_{n} x^{n}=\sum_{n=0}^{\infty}\left(\sum_{t_{1}+t_{2}+t_{3}+t_{4}=n} 1\right) x^{n} \\
& =\sum_{t_{1}=1}^{9} \sum_{t_{2}=0}^{9} \sum_{t_{3}=0}^{9} \sum_{t_{4}=0}^{9} x^{t_{1}+t_{2}+t_{3}+t_{4}} \\
& =\left(\sum_{t_{1}=1}^{9} x^{t_{1}}\right)\left(\sum_{t_{2}=0}^{9} x^{t_{2}}\right)\left(\sum_{t_{3}=0}^{9} x^{t_{3}}\right)\left(\sum_{t_{4}=0}^{9} x^{t_{4}}\right) \\
& =\left(x+x^{2}+\cdots+x^{9}\right)\left(1+x+x^{2}+\cdots+x^{9}\right)^{3} \\
& =\left(1+x+\cdots+x^{9}\right)^{4}-\left(1+x+\cdots+x^{9}\right)^{3} \\
& =\frac{\left(1-x^{10}\right)^{4}}{(1-x)^{4}}-\frac{\left(1-x^{10}\right)^{3}}{(1-x)^{3}} \\
& =\left(1-4 x^{10}+6 x^{20}-4 x^{30}+x^{40}\right) \sum_{n=0}^{\infty} C_{n+3}^{3} x^{n}-\left(1-3 x^{10}+3 x^{20}-x^{30}\right) \sum_{n=0}^{\infty} C_{n+2}^{2} x^{n},
\end{aligned}
$$

The coefficient of $x^{12}$ is
$$
a_{12}=\left(C_{12+3}^{3}-4 C_{2+3}^{3}\right)-\left(C_{12+2}^{2}-3 C_{2+2}^{2}\right)=(455-40)-(91-18)=342 .
$$

That is, there are 342 four-digit numbers whose sum of digits equals 12.