The IF() function doesn’t “collect” anything. It returns one of two alternatives given as expressions (subformulas).
If the second alternative (ELSE-case) is missing, it returns FALSE() if the condition comes out false.(IMO it should return an error in this case to avoid confusion. However, you can’t get good software if you need to be compatible with badly designed software.)
To “collect regarding conditions” we have the FILTER() function in recent LibO Calc.
The only clearly correct formula suggested above is the one by @karolus.
It avoids possible confusion by an IF() part.
Some of the results using the IF() look buggy to me because they don’t include logical FALSE() as specified for STDEVP() (also written as STDEV.P() here). A “wrongly correct” result is also a bug.
Specification: (odf 1.3)
6.18.74 STDEVP
Summary: Calculates the standard deviation using the population of a random variable, including values of type Text and Logical.