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

From |
Tirthankar Chakravarty <tirthankar.chakravarty@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Recode non-integers to positive integers |

Date |
Mon, 24 Aug 2009 11:16:58 +0100 |

Frank, I am sure you know this, but just to make sure, the line recode newvar (18=0) was specific to the "auto" dataset, and I included it because the variable "mpg" had no zeros which I could use to illustrate the solution. T On Mon, Aug 24, 2009 at 10:59 AM, Frank Gallo<fjgallo@mac.com> wrote: > Hi Nick & Tirthankar, > > Thank you for the suggestions. Here is what I did, which solved my problem: > > egen newvar = group(oldvar) > recode newvar (18=0) > replace newvar = newvar - 1 > > > Best, > Frank > > > On Aug 23, 2009, at 12:05 PM, Nick Cox wrote: > > Alternatively, > > egen newvar = group(oldvar) if oldvar != 0 > replace newvar = 0 if newvar == . > > This exploits the fact the -egen, group()- never yields 0 as a result. > > Nick > n.j.cox@durham.ac.uk > > Tirthankar Chakravarty > > Well, in your case (non-negative values) it is easy. Simply subtract 1 > from the -group-ed variable: > ******************* > sysuse auto, clear > tab mpg > recode mpg (18=0) // change 18 to 0 > egen new = group(mpg) > replace new = new - 1 > tab new > ******************* > > On Sat, Aug 22, 2009 at 4:24 PM, Frank Gallo<fjgallo@mac.com> wrote: > >> So the syntax "egen newvar = group(oldvar)" achieves my goal for one >> variable. But for another variable, I have "0" values that I want to keep >> and do not include in the grouping. I tried adding the if qualifier [egen >> newvar = group(oldvar) if oldvar > 0] but this transformed the 0s to >> missing. I would greatly appreciate any suggestions. Thank you. > > * > * 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/ > > * > * 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/ > -- To every ω-consistent recursive class κ of formulae there correspond recursive class signs r, such that neither v Gen r nor Neg(v Gen r) belongs to Flg(κ) (where v is the free variable of r). * * 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/

**Follow-Ups**:**Re: st: Recode non-integers to positive integers***From:*Frank Gallo <fjgallo@mac.com>

**References**:**Re: st: Recode non-integers to positive integers***From:*Mike Wazowski <mike.wazowski@ymail.com>

**Re: st: Recode non-integers to positive integers***From:*Frank Gallo <fjgallo@mac.com>

**Re: st: Recode non-integers to positive integers***From:*Frank Gallo <fjgallo@mac.com>

**Re: st: Recode non-integers to positive integers***From:*Tirthankar Chakravarty <tirthankar.chakravarty@gmail.com>

**RE: st: Recode non-integers to positive integers***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: Recode non-integers to positive integers***From:*Frank Gallo <fjgallo@mac.com>

- Prev by Date:
**Re: st: Recode non-integers to positive integers** - Next by Date:
**Re: st: Recode non-integers to positive integers** - Previous by thread:
**Re: st: Recode non-integers to positive integers** - Next by thread:
**Re: st: Recode non-integers to positive integers** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |