Statalist The Stata Listserver


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

Re: st: loop over pair of elements


From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: loop over pair of elements
Date   Sun, 17 Dec 2006 05:04:51 -0500

Caleb--

I think the best solution will depend on how
you want to use these files when you're done
summing variables, and how the pairs are
identified.  Assume you have two files for,
say, 1990 and 2000, and they each have the
same variables, and the pairs of id splits are
coded in a third file along the lines of:

id   year  pop
593  1990  245

id   year  pop
593  2000  125
759  2000  145

id1990  id2000
593     593
593     759

(note that this third file, encoding the
mapping from old to new, is a useful way to
organize the pairs, and could be created from
a list of pairs quite easily).

Then you could do something like:

use file2
ren id id2000
merge id2000 using file3
tab _m
drop _m
qui ds
local f `r(varlist)'
local g id1990 id2000
local all: list f - g
collapse (sum) `all', by(id1990)
ren id1990 id
append using file1

(untested, and does not preserve var labels, etc.)
but as I said, the best solution depends on the
specific application.

On 12/16/06, Caleb Southworth <[email protected]> wrote:
I have a set of pairs of observations that I would like to combine.
The new variables will be sums. This is useful, for example, when
merging historical census tracts which have been divided into two
tracts at a later time period. There are about 30 pairs of such
polygons and the operation has to be performed several times.

One solution is to identify the two observations to be merged and then
repeat this bit of code for each pair saving a temp file. For example:
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index