{"id":1308,"date":"2019-05-13T12:58:45","date_gmt":"2019-05-13T16:58:45","guid":{"rendered":"http:\/\/kaichen.work\/?p=1308"},"modified":"2019-05-13T13:04:51","modified_gmt":"2019-05-13T17:04:51","slug":"empower-and-and-or-in-if-statement-in-stata","status":"publish","type":"post","link":"https:\/\/www.kaichen.work\/?p=1308","title":{"rendered":"Empower &#8220;and&#8221; and &#8220;or&#8221; in IF statement in Stata"},"content":{"rendered":"<p>Stata is a little bit awkward when using <code>and<\/code> and <code>or<\/code> in <code>if<\/code> statement, compared to SAS. For example:<\/p>\n<p>In SAS, we can write <code>if 2001 &lt;= fyear &lt;= 2010<\/code>. But in Stata, we usually write: <code>if fyear &gt;= 2001 &amp; fyear &lt;= 2010<\/code>.<\/p>\n<p>In fact, Stata provides a handy <code>inrange<\/code> function. The above <code>if<\/code> statement can be written as: <code>if inrange(fyear, 2001, 2010)<\/code>.<\/p>\n<p>Similarly, Stata provides another <code>inlist<\/code> function. The syntax is <code>inlist(z, a, b, ...)<\/code>, which returns 1 if z = a or z = b &#8230; In <code>if<\/code> statement, it is equivalent to <code>if z = a | z = b | ...<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Stata is a little bit awkward when using and and or in if statement, compared to SAS. For example: In SAS, we can write if 2001 &lt;= fyear &lt;= 2010. But in Stata, we usually write: if fyear &gt;= 2001 &hellip; <a href=\"https:\/\/www.kaichen.work\/?p=1308\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/1308"}],"collection":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1308"}],"version-history":[{"count":10,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/1308\/revisions"}],"predecessor-version":[{"id":1318,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/1308\/revisions\/1318"}],"wp:attachment":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}