Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Collapsing with strings


From   austin nichols <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Collapsing with strings
Date   Fri, 13 Jan 2006 14:31:43 -0500

Daphna Bassok:
You may want -bys: replace- inside a loop:

foreach v of varlist put all the relevant varnames here {
 bys id (`v'): qui replace `v'=`v'[_n-1] if mi(`v')
}
bys id: drop if _n>1

may work (untested).

On 1/13/06, Marcello Pagano <pagano@hsph.harvard.edu> wrote:
> For Daphna Bassok:
> I have several duplicate observations in my data set.  However, they are
> not perfect duplicates.  Only the id # is the same. So there might be
> two observations with id#16 for instance, the first will have values for
> some variables, and missing values for others. The second also have some
> values filled and some missing.  There are no cases in which both have
> values- that is... either the first in the pair has the value OR the
> second has a value (or neither).
>
> For example: suppose I have two observations with id# 16...  The first
> has values for var1 and  2 and not 3.   The second ONLY has values for
> var 3.   What i would like to do is simply collapse these into a single
> observation with all the relevant info. meaning, 1 observation with
> id#16 that has values for all three variables.

*
*   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/



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