UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

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 multivate commands, such as, mvreg and manova.
Examples:

Double Equals -- 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.
Example:

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

This statement 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 statement when there are missing values. The missing values will get set to zero which may or may not be what you want to happen.

How to cite this page

Report an error on this page

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