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

From |
"Kieran McCaul" <Kieran.McCaul@uwa.edu.au> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Simple loop problem? |

Date |
Thu, 3 Dec 2009 10:18:51 +0800 |

... Assuming that hh_3 is coded either 0 or 1: clear input hh_id person_id hh_3 4003 01 0 4003 02 1 4003 03 0 4004 01 0 4004 02 1 4004 03 1 4005 01 0 4005 02 0 4005 03 0 end sort hh_id by hh_id:egen new_hh_3 = max(hh_3) list +------------------------------------+ | hh_id person~d hh_3 new_hh_3 | |------------------------------------| 1. | 4003 1 0 1 | 2. | 4003 2 1 1 | 3. | 4003 3 0 1 | 4. | 4004 1 0 1 | 5. | 4004 2 1 1 | |------------------------------------| 6. | 4004 3 1 1 | 7. | 4005 1 0 0 | 8. | 4005 2 0 0 | 9. | 4005 3 0 0 | +------------------------------------+ ______________________________________________ Kieran McCaul MPH PhD WA Centre for Health & Ageing (M573) University of Western Australia Level 6, Ainslie House 48 Murray St Perth 6000 Phone: (08) 9224-2701 Fax: (08) 9224 8009 email: Kieran.McCaul@uwa.edu.au ______________________________________________ If you live to be one hundred, you've got it made. Very few people die past that age - George Burns -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Robin Pleau Sent: Thursday, 3 December 2009 10:09 AM To: statalist@hsphsun2.harvard.edu Subject: st: Simple loop problem? Hello. I am using Stata 9. I have what seems like a simple coding problem but can't figure it out (I'm a relatively new Stata user). I believe the solution lies in the foreach/forvalues commands, but can't seem to come up with a solution. I need to recode a person-level variable based on whether other people in the household have the same characteristic. Specifically, I want to recode the variable hh_3 with the value of 1 (1=the person lives in a three-generational household) if anyone in the household already has hh_3=1. I want to loop through the whole dataset. hh_id person_id hh_3 4003 01 0 4003 02 1 4003 03 0 4004 01 0 4004 02 1 4004 03 1 Thank you for your help. Robin * * 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**:**st: RE: RE: Simple loop problem?***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**st: Simple loop problem?***From:*Robin Pleau <rlpleau@ucdavis.edu>

- Prev by Date:
**st: Simple loop problem?** - Next by Date:
**st: re: 3 equations, 2 endogenous Variables, 1 endogenous variable related to** - Previous by thread:
**st: Simple loop problem?** - Next by thread:
**st: RE: RE: Simple loop problem?** - Index(es):

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