[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

# RE: st: RE: how to use lag function to create sequential number

 From Sylvain Friederich To statalist@hsphsun2.harvard.edu Subject RE: st: RE: how to use lag function to create sequential number Date Sun, 11 Sep 2005 20:36:01 +0100 (BST)

```Ahem. This has the solutions Nick gave previously. Do
try either of them, paying attention to the command
syntax (bysort var: etc).

Sylvain

--- mzhang@nd.edu wrote:

> if I use the command egen id = seq(), the id will be
> a sequential number from 1
> to 29 without telling the internal group difference.
> What I tried to do to get a
> sequential variable like 1 2 ..........17 1.......5
> 1 2 3.....7 instead of 1 2
> 3..............29.
>
> Quoting Nick Cox <n.j.cox@durham.ac.uk>:
>
> > This has the solution I gave previously. Do try
> it.
> >
> > Nick
> > n.j.cox@durham.ac.uk
> >
> > mzhang@nd.edu
> >
> > > Sorry I did not state my question well. there
> are different
> > > racial groups in my
> > > sample. What i want to do is to give each racial
> group a
> > > sequential number.
> > > for example, I have 17 whites, 5 blacks and 7
> others. then
> > > the value of the
> > > sequential variable I created would be: 1 2
> 3....17 for
> > > whites; 1 2 ...5 for
> > > blacks;
> > > 1 2 ....7 for others. what I was originally
> thinking is:
> > >
> > > gen sequence=1
> > > replace sequcence=sequence+1 if l.race==race
> > >
> > > However, this does not work out as I thought.
> >
> > Nick Cox
> >
> > > > I am not aware of a lag function, i.e.
> -lag()-, in Stata. There is
> > > > a lag operator L. but that is not appropriate
> for your purpose.
> > > >
> > > > You may be in search of
> > > >
> > > > bysort race : gen id = _n
> > > >
> > > > or
> > > >
> > > > bysort race : egen id = seq()
> > > >
> > > > although note that the labelling produced is
> essentially arbitrary
> > > > in either case.
> >
> > mzhang@nd.edu
> >
> > > > > for example, there are 17 people who have
> the same ethnicity.
> > > > > If I want to give
> > > > > them a sequential number 1 2 3..........17,
> how can I use lag
> > > > > function to do this?
> >
> > *
> > *   For searches and help try:
> > *
> http://www.stata.com/support/faqs/res/findit.html
> > *   http://www.stata.com/support/statalist/faq
> > *   http://www.ats.ucla.edu/stat/stata/
> >
>
>
>
>
>
> *
> *   For searches and help try:
> *
> http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```

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