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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

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

Subject |
RE: st: RE: creating expanded records with indicator variables, where different ID's reside in the same rows |

Date |
Wed, 21 Oct 2009 18:52:40 +0100 |

OK. Try this: input a b 5 5 6 11 end gen long id = _n expand 2 if a != b bysort id : replace id = cond(_n == 1, a, b) replace a = a == id replace b = b == id l Nick n.j.cox@durham.ac.uk -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Michael McCulloch Sent: 21 October 2009 18:21 To: statalist@hsphsun2.harvard.edu Subject: Re: st: RE: creating expanded records with indicator variables, where different ID's reside in the same rows Sorry Nick, yes you're correct, it should be: id A B 5 1 1 6 1 0 11 0 1 Michael On Oct 21, 2009, at 10:18 AM, Nick Cox wrote: > Sorry, but I can't even follow your first two steps. Why isn't the > second observation 6 1 0? > > Nick > n.j.cox@durham.ac.uk > > Michael McCulloch > > I have a data structure that has been gathered as follows, where each > cell contains the subject ID if A is true, and similarly for B. > Therefore, for subject 5, I have A=yes and B=yes, whereas for subjects > 6 and 11, only B=yes. > > A B > 5 5 > 6 11 > > I'd like to transform the data structure such that each row would have > ID, and indicator variables for A and B. > id A B > 5 1 1 > 6 0 1 > 11 0 1 > > I've tried an approach like this, where I create indicator variables > but A and B, but am not sure how to "expand" from the data structure > where different ID's reside in the same rows. > . gen id1=a > . gen id2=b > . gen aa=1 if a!=. > . gen bb=1 if b!=. > > It also looks like -reshape- is not suitable because different ID's > reside in the same rows. > Any advice would be appreciated. * * 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/

**References**:**Re: st: RE: creating expanded records with indicator variables, where different ID's reside in the same rows***From:*Michael McCulloch <mm@pinest.org>

- Prev by Date:
**Re: st: creating expanded records with indicator variables, where different ID's reside in the same rows** - Next by Date:
**Re: st: Too much time to draw a graph** - Previous by thread:
**Re: st: RE: creating expanded records with indicator variables, where different ID's reside in the same rows** - Index(es):

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