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: RE: Creating all permutations of station pairs with differing urbanity


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: Creating all permutations of station pairs with differing urbanity
Date   Mon, 27 Sep 2010 18:12:48 +0100

See the help on -cross-. 

Nick 
[email protected] 

Zeke Hausfather

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.


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