[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Neumayer,E" <E.Neumayer@lse.ac.uk> |

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

Subject |
st: RE: RE: RE: Resdesigning dyadic data formats |

Date |
Wed, 21 Apr 2004 14:23:34 +0100 |

Nick, great! Now, one more complication. Your advice works if there are dyads in just one year. But assume now that there is also a year variable. OK, with "fillin c1 c2 year" I get the dataset in a nice rectangular shape. What adjustment do I need to make for the other four lines: gen max = max(c1,c2) gen min = min(c1,c2) bysort max min (x) : assert _N == 2 by max min: replace x = x[1] if missing(x) Thanks, Eric -----Original Message----- From: Nick Cox [mailto:n.j.cox@durham.ac.uk] Sent: 21 April 2004 11:49 To: statalist@hsphsun2.harvard.edu Subject: st: RE: RE: Resdesigning dyadic data formats (not tested; shorter solutions may exist) gen max = max(c1,c2) gen min = min(c1,c2) bysort max min (x) : assert _N == 2 by max min: replace x = x[1] if missing(x) For example: 2-1 and 1-2 both have maximum 2 and minimum 1. We sort so that ties on -min- and -max- are together, and check that they do indeed occur in pairs. Within each pair, we sort on -x-, so that missings go to the end. Then we copy downwards within each pair. Nick n.j.cox@durham.ac.uk Neumayer,E > > thanks. I can see how this creates a nice rectangular > dataset. However, how could I get Stata to take the values of > the x-variables over? At the moment, the "1-2" pair, for > example, has 567 as value for the x-variable, but after > fillin, the "2-1" pair, which now exists, is empty for the > x-variable, but I'd like to have it as 567 as well. Any help > greatly appreciated again. > > Best, Eric > > ------------------------------ > > Date: Tue, 20 Apr 2004 14:18:13 +0100 > From: "Nick Cox" <n.j.cox@durham.ac.uk> > Subject: st: RE: Resdesigning dyadic data formats > > fillin c1 c2 > replace x = . if _fillin > drop _fillin > > Nick > n.j.cox@durham.ac.uk > > Neumayer,E > > > I have a "dyadic" dataset that looks like this (which is the > > traditional way of setting up such data): > > > > c1 c2 x > > 1 2 567 > > 1 3 345 > > 1 4 7 > > 1 5 348 > > 2 3 47 > > 2 4 3 > > 2 5 48 > > 3 4 23424 > > 3 5 347 > > 4 5 234 > > > > The "c1" and "c2" are identifiers for the two dyads. I would > > like to re-design the data to have it in the following format: > > > > c1 c2 x > > 1 1 > > 1 2 567 > > 1 3 345 > > 1 4 7 > > 1 5 348 > > 2 1 567 > > 2 2 > > 2 3 47 > > 2 4 3 > > 2 5 48 > > 3 1 345 > > 3 2 47 > > 3 3 > > 3 4 23424 > > 3 5 347 > > 4 1 7 > > 4 2 3 > > 4 3 23424 > > 4 4 > > 4 5 234 > > 5 1 348 > > 5 2 48 > > 5 3 347 > > 5 4 234 > > 5 5 > > > > Note that now the identical pairs (1-1, 2-2, 3-3, 4-4, 5-5) > > have missing x-values, of course, and that all x-values exist > > twice now (e.g., once for 1-5, and once for 5-1). I know, one > > could do this redesigning by hand, but given that my actual > > dataset is far bigger, I am looking for a way to let Stata do > > the work for me. Any ideas? * * 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/ * * 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/

- Prev by Date:
**RE: st: RE: ln1=0 for missing values** - Next by Date:
**Re: st: RE: RE: RE: RE: graph combine, asis** - Previous by thread:
**st: RE: ln1=0 for missing values** - Next by thread:
**st: RE: RE: RE: RE: graph combine, asis** - Index(es):

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