Skip to main content

Research Repository

Advanced Search

Stata tip 151: Puzzling out some logical operators

Cox, Nicholas J.

Stata tip 151: Puzzling out some logical operators Thumbnail



The logical operators & (“and”) and | (“or”) can sometimes be tricky in statistical software such as Stata. They are extremely useful, so you need to understand thoroughly how they work. Any trickiness arises mostly in translating from ordinary language to a statistical computer language. Here I survey various common confusions and explain what to do instead.


Cox, N. J. (2023). Stata tip 151: Puzzling out some logical operators. The Stata Journal, 23(1),

Journal Article Type Article
Acceptance Date Feb 8, 2023
Online Publication Date Apr 5, 2023
Publication Date 2023
Deposit Date Apr 20, 2023
Publicly Available Date Apr 20, 2023
Journal The Stata Journal: Promoting communications on statistics and Stata
Print ISSN 1536-867X
Electronic ISSN 1536-8734
Publisher SAGE Publications
Peer Reviewed Peer Reviewed
Volume 23
Issue 1
Public URL


Published Journal Article (106 Kb)

Publisher Licence URL

Copyright Statement
This article is distributed under the terms of the Creative Commons Attribution 4.0 License ( which permits any use, reproduction and distribution of the work without further permission provided the original work is attributed as specified on the SAGE and Open Access pages (

You might also like

Downloadable Citations