{"title":"Stata tip 152: if and if: When to use the if qualifier and when to use the if command","authors":"N. Cox, C. Schechter","doi":"10.1177/1536867x231175349","DOIUrl":null,"url":null,"abstract":"Stata has an if qualifier and an if command. Here we discuss generally when you should use either and specifically flag a common pitfall in using the if command. In a nutshell, the pitfall arises from confusing the two constructs: the if command does not loop over the data but, at most, looks in the first observation of a dataset. There has long been a StataCorp FAQ on this topic (Wernow 2005), but we and others have usually tried to explain matters otherwise. This tip is intended as a more durable version of the story that should be easier to find than occasional Statalist postings that are vivid when read but hard to find later.","PeriodicalId":51171,"journal":{"name":"Stata Journal","volume":null,"pages":null},"PeriodicalIF":3.2000,"publicationDate":"2023-06-01","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Stata Journal","FirstCategoryId":"100","ListUrlMain":"https://doi.org/10.1177/1536867x231175349","RegionNum":2,"RegionCategory":"数学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"Q1","JCRName":"SOCIAL SCIENCES, MATHEMATICAL METHODS","Score":null,"Total":0}
引用次数: 0
Abstract
Stata has an if qualifier and an if command. Here we discuss generally when you should use either and specifically flag a common pitfall in using the if command. In a nutshell, the pitfall arises from confusing the two constructs: the if command does not loop over the data but, at most, looks in the first observation of a dataset. There has long been a StataCorp FAQ on this topic (Wernow 2005), but we and others have usually tried to explain matters otherwise. This tip is intended as a more durable version of the story that should be easier to find than occasional Statalist postings that are vivid when read but hard to find later.
期刊介绍:
The Stata Journal is a quarterly publication containing articles about statistics, data analysis, teaching methods, and effective use of Stata''s language. The Stata Journal publishes reviewed papers together with shorter notes and comments, regular columns, book reviews, and other material of interest to researchers applying statistics in a variety of disciplines.