4. Given the sequence $\left\{a_{n}\right\}$ satisfies:
$$
a_{1}=-2 \text {, }
$$

and $S_{n}=\frac{3}{2} a_{n}+n$ ( $S_{n}$ is the sum of the first $n$ terms of the sequence $\left\{a_{n}\right\}$).
$f(x)$ is an odd function defined on $\mathbf{R}$, and satisfies
$$
f(2-x)=f(x) \text {. }
$$

Then $f\left(a_{2021}\right)=$ $\qquad$
4.0.

Given that $f(x)$ is an odd function defined on $\mathbf{R}$ and satisfies $f(2-x)=f(x)$,
we know that $f(-x)=f(x+2)=-f(x)$, $f(x+4)=-f(x+2)=f(x)$.
Thus, the smallest positive period of $f(x)$ is 4.
Since the sequence $\left\{a_{n}\right\}$ satisfies $a_{1}=-2$, and
$$
S_{n}=\frac{3}{2} a_{n}+n,
$$

Therefore, when $n \geqslant 2$, we have
$$
S_{n-1}=\frac{3}{2} a_{n-1}+n-1 \text {. }
$$
(1) - (2) gives
$$
\begin{array}{l}
a_{n}=\frac{3}{2} a_{n}-\frac{3}{2} a_{n-1}+1 \\
\Rightarrow a_{n}=3 a_{n-1}-2 \\
\Rightarrow a_{n}-1=3\left(a_{n-1}-1\right) .
\end{array}
$$

Thus, $\left\{a_{n}-1\right\}$ is a geometric sequence with the first term -3 and common ratio 3.
$$
\begin{array}{l}
\text { Then } a_{n}-1=-3^{n} \\
\Rightarrow a_{n}=1-3^{n} \\
\Rightarrow a_{2021}=1-3^{2021} . \\
\text { Also } 3^{2021}=(4-1)^{2021} \\
=4^{2021}+\cdots+C_{2021}^{1}(-1) \times 4^{2020}-1,
\end{array}
$$

Thus, $3^{2021}$ leaves a remainder of 3 when divided by 4.
$$
\begin{array}{l}
\text { Therefore, } f\left(a_{2021}\right)=f\left(1-3^{2021}\right)=-f\left(3^{2021}-1\right) \\
=-f(-1-1)=f(2)=f(0)=0 .
\end{array}
$$