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

From |
Jeph Herrin <junk@spandrel.net> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Wed, 21 Oct 2009 13:54:22 -0400 |

How about create two files and merge preserve keep if !mi(A) ren A ID gen byte A=1 sort ID save theAs restore keep if !mi(B) ren B ID gen byte B=1 sort ID merge 1:1 ID using theAs replace A=0 if mi(A) replace B=0 if mi(B) ? hth, Jeph Michael McCulloch wrote:

Hello,I have a data structure that has been gathered as follows, where eachcell 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 6and 11, only B=yes.A B 5 5 6 11I'd like to transform the data structure such that each row would haveID, and indicator variables for A and B.id A B 5 1 1 6 0 1 11 0 1I've tried an approach like this, where I create indicator variables butA and B, but am not sure how to "expand" from the data structure wheredifferent 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'sreside in the same rows.Any advice would be appreciated. Michael McCulloch Pine Street Foundation 124 Pine Street San Anselmo, CA 94960-2674 tel: 415-407-1357 fax: 206-338-2391 mm@pinestreetfoundation.org * * 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/

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

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

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