Statalist


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

RE: st: creating age variable for all ids


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: creating age variable for all ids
Date   Thu, 29 May 2008 18:16:48 +0100

Another way to do it: 

Suppose you want ages 60(5)80, ids 1/100. 

set obs 500
egen id = seq(), block(5)
egen age = seq(), from(12) to(16)
replace age = 5 * age 

Nick 
n.j.cox@durham.ac.uk 

MAY BAYDOUN

Thank you so much! I really appreciate this,

Eva Poen

> Here is one way to do it. Note that I start from
> scratch to create the
> ID variable. You can start with -expand-.
> 
> *********************
> clear
> set obs 5
> gen id = _n
> expand 5
> sort id
> list
> bysort id: gen age = 55+(_n*5)
> list
> **********************
 
 2008/5/29 MAY BAYDOUN <mbaydoun2002@yahoo.com>:

> > I am trying to create a dataset in which I already
> > have the id numbers but I would like to replicate
> them
> > and add another variable age that has exactly the
> same
> > values for all ids. So, the original file is:
> >
> > id
> > 1
> > 2
> > 3
> > 4
> > 5
> >
> > The file I want to create is:
> >
> > id   age
> > 1    60
> > 1    65
> > 1    70
> > 1    75
> > 1    80
> > 2    60
> > 2    65
> > 2    70
> > 2    75
> > 2    80
> > ..
> >

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index