Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: recode values using -foreach- and a numlist (possibly)


From   "David Winter" <d.l.winter@bham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: recode values using -foreach- and a numlist (possibly)
Date   Mon, 28 Nov 2005 17:23:57 -0000

Hello,

I have some data resulting from -stset- and -stsplit- where the -at- list was:
1900 1971(1)2006, into a variable 'calp' .  The resulting data looks like:

Sex    calp  observed 
===    ====  ========
1      1900       9
1      1971      10
1      1972      23
1      1973       2
..     ....      ..
1      2006      18

I should like to group 'calp' and generate a new variable (nvar) according to a defined -numlist-, e.g.

for each value in numlist (1900 1980 1990 2000) generate a value for nvar

so:

if calp >= 1900 and calp <= 1979 then nvar = 1900
if calp >= 1980 and calp <= 1989 then nvar = 1980
if calp >= 1990 and calp <= 1999 then nvar = 1990
if calp >= 2000 then nvar = 2000

Can this be done using the -foreach- command? 

Best wishes,

Dave 

***********************************************************
Mr David L. Winter, HNC
IT Manager (BCCSS Study)
Department of Public Health & Epidemiology
University of Birmingham
Edgbaston
Birmingham
B15 2TT
UK
tel: +44 (0)121 4146766
fax: +44 (0)121 4147923
***********************************************************


*
*   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