Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Creating all permutations of station pairs with differing urbanity


From   Zeke Hausfather <[email protected]>
To   [email protected]
Subject   st: Creating all permutations of station pairs with differing urbanity
Date   Mon, 27 Sep 2010 13:07:07 -0400

I'm working on a project that requires creating all possible
permutations of urban and rural temperature measurement station pairs.
Specifically, I want a database that has urban pair id (integer),
rural pair id (integer), and pair id (string with both urban pair id
and rural pair id separated by an underscore).

I'm starting with a dataset with two columns: station_id (integer),
and urbanity (boolean -- 1 or 0)

I want to create a new dataset with all possible permutations of 1
urban and 1 rural station. My initial attempt was:


gen urban_id_list = station_id if urban == 1
gen rural_id_list = station_id if urban == 0
save base_data.dta

foreach urban_id in urban_id_list {
    foreach rural_id in rural_id_list {
        gen rural_pair = `rural_id' if `urban_id' != . & `rural_id' != .
        gen urban_pair = `urban_id' if `urban_id' != . & `rural_id' != .
        gen pair_id = "`urban_id'_`rural_id'" if `urban_id' != . &
`rural_id' != .
        save temp_data.dta, replace

        use pair_database.dta
        append using temp_data.dta
        save pair_database.dta, replace

        use base_data.dta
    }
}

clear
use pair_database.dta


But this doesn't seem to work at all.

Any thoughts?

--
Zeke Hausfather
Chief Scientist

Efficiency 2.0
165 William Street, Floor 10
New York, NY 10038
T. 646 478 8509
M. 914 589 3900
F. 347 328 9342

[email protected]
efficiency20.com

This electronic message originates from Efficiency 2.0, LLC. The
information contained in this message may be legally privileged and
confidential under applicable law. If you are not the intended
recipient you are hereby notified that any dissemination, copy or
disclosure of this communication is strictly prohibited. If you have
received this communication in error, please notify the sender and
purge the communication immediately without making any copy or
distribution.

Please consider the environment before printing this email.

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index