[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 |
st: RE: AW: How to add the same block of data to every individual |

Date |
Wed, 8 Apr 2009 16:39:46 +0100 |

Equivalently: expand 3 bysort id : gen y = cond(_n == 1, "a", cond(_n == 2, "b", "c")) by id : gen z = cond(_n == 1, 7, cond(_n == 2, 8, 9)) or, in this example, by id : gen z = _n + 6 Nick n.j.cox@durham.ac.uk Martin Weiss It really depends where you want to take this exercise next, but here is a shot at the prob: ************* clear* inp id x 1 4 2 6 3 7 end expand 3 bys id: g str1 y="a" by id: replace y="b" if _n==2 by id: replace y="c" if _n==3 by id : egen float z = seq(), from(1) to(3) block(1) l, noo sepby(id) ************* Quang Nguyen Suppose I have the following data set: id x 1 4 2 6 3 7 .................. and a "data block" as follows: y z a 7 b 8 c 9 Do you know how I can add this data block to every individual in the idividial data set. After adding, the new data set will look like the following: id x y z 1 4 a 7 1 4 b 8 1 4 c 9 2 6 a 7 2 6 b 8 2 6 c 9 ---------------------------- * * 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: How to add the same block of data to every individual***From:*Quang Nguyen <quangn@gmail.com>

**st: AW: How to add the same block of data to every individual***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**Re: st: AW: How to add the same block of data to every individual** - Next by Date:
**Re: st: AW: How to add the same block of data to every individual** - Previous by thread:
**st: AW: How to add the same block of data to every individual** - Next by thread:
**Re: st: AW: How to add the same block of data to every individual** - Index(es):

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