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: Replacing values


From   Roberto Ferrer <[email protected]>
To   Stata Help <[email protected]>
Subject   st: Replacing values
Date   Tue, 9 Jul 2013 22:12:22 +0100

For every possible year in the data, I want to replace the missing
values of the variable pop_region using the corresponding value of
variables state and district of year 2005. So the first value of
pop_region in the example
should be 25, the second 25, ..., the sixth 50, the eighth 62, etc.

year  state  district  st_pop  pop_region
1995   a         1           100         .
1995   a         2           100         .
1995   a         2           100         .
1995   a         2           100         .
1995   a         2           100         .
1995   a         3           100         .
1995   a         3           100         .
1995   b         1           200         .
--------------------------------------------------------
2005   a         1           100         25
2005   a         2           100         25
2005   a         3           100         50
2005   a         3           100         50
2005   b         1           200         62
2005   b         1           200         62
2005   b         1           200         62
2005   b         1           200         62

I tried this (and other stuff) which seems too involved for the task
and doesn't work of course:

levelsof year, local(lyear)
levelsof state, local(lstate)
levelsof district, local(ldistrict)

foreach y of local lyear {
    foreach s of local lstate {
        foreach r of local ldistrict {
             local reval = pop_region if yearobs==2005 & state==`s' &
district==`r'
             replace pop_region = `reval' if state == `s' & district == `r'
        }
    }
}

Thanks.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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