. gen x = 0.1 . count if x == 0.1 0To avoid this issue, you could store your numbers with decimal points as doubles.
. gen double n = 0.1 . count if n == 0.1 1But this uses twice as much space to store, and you can't use this method if you are using variables that have been entered or created by someone else. Instead, use the float function when doing comparaisons, which rounds numbers to float accuracy.
. count if float(x) == float(0.1) 1
if varx evaluates to TRUE if varx is missing, so if varx is a binary variable, your command will be executed for observations where varx is equal to 1 and where it's missing. This is probably not what you want.
Later versions of Stata support extended missing values such as .a and .b Some datasets use these extended missing values to differentiate between different reasons why the value is missing (for example .a might mean "don't know" while .b means "not applicable.") All of these extended missing values are counted by Stata as being greater than any number so if you want to restrict your command to observations where varx is not missing, use if varx < . to be safe. Similarily, if you want to drop all observations where varx is missing, use drop if varx >= . instead of drop if varx == .
last modified: 31 July 2014