Hi everyone! Apologies for the vague title. I have a variable (URBAN) that defines each village (IDPSU) as Urban (=1) or rural (=0). I have two time periods here. In the second time period (time==1), there are some changes to the urban/rural classification for villages (a -previously rural village is now urban due to development). And Some villages may have been added and/or removed. I need to create a new variable which records URBAN values for time=0 for all the villages and retains its original value if the village was added in the second time period.
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long IDPSU float time int URBAN
10206 0 1
11311 0 1
10301 0 1
10302 0 1
10206 0 1
11203 0 0
10206 0 1
10206 0 1
10206 0 1
10206 0 1
10206 0 1
10206 0 1
11204 0 0
10206 0 1
10206 0 1
10206 0 1
10206 0 1
10206 0 1
10206 0 1
10206 0 1
10207 0 1
11310 0 1
11313 0 1
10205 0 0
10205 0 0
10205 0 0
10205 0 0
10205 0 0
10205 0 0
10205 0 0
10205 0 0
10205 0 0
10205 0 0
10308 0 1
10205 0 0
10204 0 0
10307 0 1
10207 0 1
11312 0 1
10204 0 0
10204 0 0
10204 0 0
10204 0 0
10204 0 0
10505 0 0
10506 0 0
10204 0 0
10204 0 0
11312 0 1
10204 0 0
10204 0 0
10204 0 0
10204 0 0
11311 0 1
10204 0 0
10307 0 1
10204 0 0
10204 0 0
10204 0 0
11301 0 0
10204 0 0
10204 0 0
10304 0 1
11313 0 1
10204 0 0
10202 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10304 0 1
10206 0 1
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
11203 0 0
10203 0 0
10203 0 0
10502 0 0
11201 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
10203 0 0
end
label values URBAN URBAN
label def URBAN 0 "Rural", modify
label def URBAN 1 "Urban", modify