Single equal: Set equal
The single equal, =, is used as a set equal operator. Old time Pascal programmers will recognize it as, :=. It is used in the generate, replace and recode commands. Examples:
generate tot = read + write + math replace mean = total/freq recode x 5=1 4=2 2=4 1=5
The single equal is also used in some of the multivariate commands, such as, mvreg and manova. For example,
mvreg read write math science = gpa gender honors manova read write math science = gender program gender*program
Double equal: Test for equality
The double equals, ==, is used to test for equality. It is sometimes called logical equals because it is part of a logical test that returns either a one (true) or a zero (false). Here are some examples:
regress write read female if ses==2 list read write math if prog==1 assert gender==1
The double equals can also be used in an if command in a do-file or ado-file. For example,
if stage==2 { local s2 "stage 2 analysis" display `s2' regress yvar `xvar1' `xvar2' }
You can create some interesting commands that have both a single equal and double equal signs. For example,
generate hises = ses==2
This command creates a zero/one variable, hises. The expression ses==2 has the value of one when ses (logically) equals two and has the value zero otherwise. You need to take care when using this type of command when there are missing values. The missing values will get set to zero which may or may not be what you want.