  Given a group word $w$ in $k$ variables, a finite group $G$ and $g\in G$, we
consider the number $N_{w,G}(g)$ of $k$-tuples $g_1,\dots ,g_k$ of elements of
$G$ such that $w(g_1,\dots ,g_k)=g$. In this work we study the functions
$N_{w,G}$ for the class of nilpotent groups of nilpotency class $2$. We show
that, for the groups in this class, $N_{w,G}(1)\geq |G|^{k-1}$, an inequality
that can be improved to $N_{w,G}(1)\geq |G|^k/|G_w|$ ($G_w$ is the set of
values taken by $w$ on $G$) if $G$ has odd order. This last result is explained
by the fact that the functions $N_{w,G}$ are characters of $G$ in this case.
For groups of even order, all that can be said is that $N_{w,G}$ is a
generalized character, something that is false in general for groups of
nilpotency class greater than $2$. We characterize group theoretically when
$N_{x^n,G}$ is a character if $G$ is a $2$-group of nilpotency class $2$.
Finally we also address the (much harder) problem of studying if
$N_{w,G}(g)\geq |G|^{ k-1}$ for $g\in G_w$, proving that this is the case for
the free $p$-groups of nilpotency class $2$ and exponent $p$.
