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

From |
"Ashim Kapoor" <ashimkapoor@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: variable that counts double observations.. |

Date |
Wed, 12 Nov 2008 20:58:42 +0530 |

Nick, I know it is not exactly what is written but it does the job of grouping 2 consecutive variables and hence can be used in the by command. To refine it you may say egen j=group(var) then we will have 1 1 2 2 3 3 etc. By the way I never got your 1st post. Email got eaten up I guess. Thank you, Ashim. On Wed, Nov 12, 2008 at 8:48 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote: > The first line won't work, as already explained in my earlier posting. > > But suppose you had a variable with values 1 up. > > The second line would replace 1,2,3,4,5,6, ... with 1,1,3,3,5,5,... > which is not what I think is being asked for. > > Nick > n.j.cox@durham.ac.uk > > Ashim Kapoor > > > egen var=_n , by(group) > by group : replace var=var-1 if mod(var,2)==0 > > I think this should work. > > What the second line says is that for every even number var should > have the value of the previous var which is itself -1 . > > Can someone approve this ? I am not 100% certain. > > On Wed, Nov 12, 2008 at 4:36 PM, Linn Renée Naper <linn.naper@ecgroup.no> wrote: > >> egen var=_n, by(group) will give me a variable counting from 1 til N within each group of the data. >> BUT: how do I tell stata that the observations are double in the sense that I need a variable that repeats each number ones, >> like this: 11 22 33 44.... instead of 1 2 3 4..... >> I need this variable in order to collapse the data. > > * > * 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/

**Follow-Ups**:**RE: st: variable that counts double observations..***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**st: variable that counts double observations..***From:*Linn Renée Naper <linn.naper@ecgroup.no>

**Re: st: variable that counts double observations..***From:*"Ashim Kapoor" <ashimkapoor@gmail.com>

**RE: st: variable that counts double observations..***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**RE: st: variable that counts double observations..** - Next by Date:
**st: RE: Table of relative frequencies** - Previous by thread:
**RE: st: variable that counts double observations..** - Next by thread:
**RE: st: variable that counts double observations..** - Index(es):

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