I have a player who is playing a beast master ranger and I was wondering: do I calculate the level of the animal companion when making encounters?
Not for the Beast Master Companion
The beast companion for that Ranger is granted by their class features. This makes it for all intents and purposes part of the Ranger (and included in their levels, as it were). In particular it uses their initiative and their actions to make attacks, meaning they are not an independent creature contributing to encounters. For these same reasons the Beast Master is often considered a slightly weaker subclass, so increasing the encounter difficulty because of them is not a good idea.
It may be helpful to think of the Beast Master Companion in a similar light to creatures conjured through spells; such as conjure animals or summon lesser demons. These additional creatures can definitely affect the difficulty of the encounter, but they are accounted as part of the PC's features and resources and are thus similarly included in their levels.
Only if the party gains companions (animalian or otherwise) through mechanisms that aren't their class will you need to make such adjustments. There is some advice in this question's answers, but the short answer is that you will have to do some trial and error, as you realistically will have to do for any party. (And even more so when they are given extra stuff; like magical items.)