Stator vanes, or to use the more accurate term " guide vanes " have two fundamental functions.
At the cold end, they angle the airflow at the optimum setting onto the face of the rotating blades for both the linear velocity of the airflow, and the velocity with respect to the speed of sound. This prevents compressor stall, and in multi spool engines a la RB211 ( ah, Rolls Royce ) they - along with bleed valve scheduling - prevent compressor mismatch and thus make the stall or surge margines more user friendly.
These cold end guide vanes ( called inlet guide vanes right at the front, or interstage guide vanes further back along the gas path ) are variable in angle, dependent upon spool RPM and a few other things, and there can be many stages of variable guide vanes in the compressor. It is because these vanes are moveable that the term "stator vanes" fell into disuse.
A secondary, but none the less important function is to reduce the velocity of the gas stream and increase the pressure, thus making the compressor stage more efficient.
At the hot end the function is much the same primarily as it is for the cold end, except that the secondary function is to increase the linear velocity of the hot gases to keep them as near as possible to mach 1, thus making the multi stage turbines more efficient and closer matched in effort to each other.
Hot end guide vanes ( called nozzle guide vanes ) are usually fixed, although some high performance military applications are being developed with variable hot end vanes as well.
The overall effect is a much more efficient engine which is also much quieterand less susceptible to surging.
Hope this helps.