Liz's Stata Guide

Mistakes I Have Made

This page is dedicated to the various mistakes that I have made using Stata. Learn from them! Have you made a mistake using Stata that you think others could learn from? Email me at djiboliz@gmail.com.

using if varx instead of if varx == 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.

using if varx != . instead of if varx < .

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 == .

contact: djiboliz@gmail.com
last modified: 2 May 2007