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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"PHAM Ngoc Minh" <[email protected]> |

To |
<[email protected]> |

Subject |
st: RE: using -cond- to create a indicator |

Date |
Fri, 26 Oct 2012 17:14:26 +0900 |

```
Dear Nick,
This command does work well, and is easy to remember. Great thanks to your
quick replies.
Sincerely,
Minh
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: Friday, October 26, 2012 4:59 PM
To: [email protected]
Subject: Re: using -cond- to create a indicator [was: Re: st: intcens: how
to estimate mean and variance after intcens]
Although I am fond of -cond()- I would usually write here
generate wcgrp = wc>90&sex==1 | wc>80&sex==2 if wc < .
Nick
On Fri, Oct 26, 2012 at 8:37 AM, Maarten Buis <[email protected]>
wrote:
> On Fri, Oct 26, 2012 at 6:22 AM, PHAM Ngoc Minh wrote:
>> I wish to create dummy variables containing missing (.), and thus used
>> formula COND(IF, THEN, ELSE) but missing (.) no longer existed. An
example
>> as follows:
>>
>> I need to generate (wcgrp) from waist circumference (wc) as 1, 0 or
missing
>> (.), then typed:
>>
>> generate wcgrp = cond(wc>90&wc!=.&sex==1|wc>80&wc!=.&sex==2, 1, 0)
>>
>> but (wcgrp) had only 1 and 0, and missing was regarded as 0.
>
> What you want is a new variable that contains three possible values
> (0, 1, .) but you give it values using a function that can only output
> 2 values (one for when the expression is true and one for when the
> expression is false), so that cannot work. Notice however that
> -cond()- is working correctly in the sense that it did exactly what
> you told it to do: it gives a 0 when the expression is false and the
> expression is false when either the waist circumference is smaller
> than some sex specific threshold or when wc is missing.
>
> Below are two possible solutions:
>
> generate wcgrp = cond(wc>90&sex==1|wc>80&sex==2, 1, 0) if !missing(wc)
>
> generate wcgrp = cond(wc>90&sex==1|wc>80&sex==2, cond(missing(wc), ., 1),
0)
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
```

**References**:

- Prev by Date:
**st: RE: using -cond- to create a indicator** - Next by Date:
**Re: st: Create Timeline based on Dates** - Previous by thread:
**Re: using -cond- to create a indicator [was: Re: st: intcens: how to estimate mean and variance after intcens]** - Next by thread:
**st: RE: using -cond- to create a indicator** - Index(es):