The $() identifier is an alias for $eval(), so in effect you're un-necessarily using $eval() twice. Plus you now don't even have a term#2. When you use the == operator it's required to have a term#2, even if you use $null.

Also, you don't want to evaluate the assembled variable once, because as the 3 echoes showing the 3 levels of evaluation, you're comparing a string beginning with a percent sign against 'nothing', which will never be true.

If you've correctly loaded the %ageCount variable with the value of the dynamic variable, you could use %ageCount inside your if() statement instead of repeating the assembly of the dynamic variable again.