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

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

From |
Maarten Buis <maartenlbuis@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
using -cond- to create a indicator [was: Re: st: intcens: how to estimate mean and variance after intcens] |

Date |
Fri, 26 Oct 2012 09:37:51 +0200 |

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) Hope this helps, Maarten --------------------------------- Maarten L. Buis WZB Reichpietschufer 50 10785 Berlin Germany http://www.maartenbuis.nl --------------------------------- * * 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/

**Follow-Ups**:**st: RE: using -cond- to create a indicator***From:*"PHAM Ngoc Minh" <pham@ri.ncgm.go.jp>

**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:
**RE: st: intcens: how to estimate mean and variance after intcens** - Next by Date:
**RE: st: mi impute chained** - Previous by thread:
**st: convergence problems in mi impute chained** - Next by thread:
**Re: using -cond- to create a indicator [was: Re: st: intcens: how to estimate mean and variance after intcens]** - Index(es):