UCLA Academic Technology Services HomeServicesClassesContactJobs
Help the Stat Consulting Group by giving a gift             
Loading

Stata FAQ
What is the difference between = and == in Stata?

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:

The single equal is also used in some of the multivariate commands, such as, mvreg and manova. For example,

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:

The double equals can also be used in an if command in a do-file or ado-file.  For example,

You can create some interesting commands that have both a single equal and double equal signs.  For example,

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.

How to cite this page

Report an error on this page or leave a comment

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.