Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
"PHAM Ngoc Minh" <pham@ri.ncgm.go.jp> |

To |
<statalist@hsphsun2.harvard.edu> |

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: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: Friday, October 26, 2012 4:59 PM To: statalist@hsphsun2.harvard.edu 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 <maartenlbuis@gmail.com> 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**:**using -cond- to create a indicator [was: Re: st: intcens: how to estimate mean and variance after intcens]***From:*Maarten Buis <maartenlbuis@gmail.com>

**Re: using -cond- to create a indicator [was: Re: st: intcens: how to estimate mean and variance after intcens]***From:*Nick Cox <njcoxstata@gmail.com>

- 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):