Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# RE: st: gen a variable

 From Nick Cox <[email protected]> To "'[email protected]'" <[email protected]> Subject RE: st: gen a variable Date Thu, 22 Mar 2012 16:05:53 +0000

```I agree with the spirit here but note that

a == 1 & b == 1 & c == 1

is not translated by

inlist(1, a, b, c)

The latter is: is _any_ of a, b, c equal to 1? Not: are _all_ of a, b, c equal to 1?

This is easier to see with numerical examples, say

. di inlist(1,1,2,2)
1

Nick
[email protected]

daniel klein

Chiara,

Nick and Maarten already pointed to -egen- as a possible solution.

Aside from your question I would like to add, that expressions like

if cond3==1 & age>=15 & age<=64 & dipind==1 & hours>20 & hours<55 &
occupation==1

may in a lot of cases be easier written using -inlist() and
-inrange()- function as in

if  inlist(1, cond3, dipind, occupation) & inrange(age, 15, 64) &
inrange(hours, 20, 55)

Note however that -inrange(z, a, b)- returns one if a <= z <= b.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```