[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Collapsing with strings
Yes, as usual, a cleaner and much more simple solution to Daphna's duplicates
problem than mine, staircase or not!
- Gary
Nick Cox wrote:
L'esprit de l'escalier:
When observations come in blocks of 2 another
approach is possible that removes the need for
sorting on each variable, although one prior
sort id
is needed.
foreach var of varlist var1-var3 {
by id: replace `var' = `var'[3 - _n] if missing(`var')
}
When the missing values are in the first observation, _n
is 1 and 3 - _n is 2. When the second, _n is 2 and 3 - _n
is 1. Hence 3 - _n indexes the other observation in blocks
of 2. This works regardless of variable type.
*
* 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/