I have 2-year panel data for households and it's members. I have a variable ramadan09 which is defined for the year 2009 and has missing values for 2007. I want to replace the 2007 missing values with 2009 values of the same variable (i.e. ramadan07) or a new variable that simply copies 2009 ramadan09 values but define it for the year 2007.
For example in 2009, HH with branchid-1, spotno-23, and hhno-10 was not interviewed during Ramadan (i.e. ramadan09=0), I want 0 for this household in 2007 as well.
I've read STATA FAQ's on this written by Nic Cox and it was of great help but I guess the problem at hand is a bit more complicated. Any help in this regard will be highly appreciated.
Some additional notes
- The data was collected for all hh-members and it's for this reason why I have multiple observations per branchid,spotno and hhno. There is no unique identifier in the data but branchid, spotno and hhno together define a household.
- It's possible that 5 hh members were interviewed in 2009 but only 4 were interviewed in 2007 (or vice-versa)
- It's not possible for a HH [branchid, spotno, hhno] to have both 1 and 0 in ramadan09
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int year byte branchid int(spotno hhno) float ramadan09 2007 1 23 10 . 2007 1 23 10 . 2007 1 23 10 . 2007 1 23 10 . 2007 1 23 10 . 2007 1 23 10 . 2007 1 23 10 . 2007 1 23 10 . 2007 1 23 10 . 2007 1 23 10 . 2007 1 23 10 . 2009 1 23 10 0 2009 1 23 10 0 2009 1 23 10 0 2009 1 23 10 0 2009 1 23 10 0 2009 1 23 10 0 2009 1 23 10 0 2009 1 23 10 0 2009 1 23 10 0 2009 1 23 10 0 2009 1 23 10 0 2009 1 23 10 0 2007 1 23 14 . 2007 1 23 14 . 2007 1 23 14 . 2009 1 23 14 0 2009 1 23 14 0 2009 1 23 14 0 2007 1 23 24 . 2007 1 23 24 . 2007 1 23 24 . 2007 1 23 24 . 2007 1 23 24 . 2007 1 23 24 . 2007 1 23 24 . 2007 1 23 24 . 2007 1 23 24 . 2007 1 23 24 . 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2009 1 23 24 0 2007 1 23 30 . 2007 1 23 30 . 2007 1 23 30 . 2007 1 23 30 . 2009 1 23 30 0 2009 1 23 30 0 2009 1 23 30 0 2009 1 23 30 0 2007 1 23 36 . 2007 1 23 36 . 2007 1 23 36 . 2007 1 23 36 . 2007 1 23 36 . 2009 1 23 36 0 2009 1 23 36 0 2009 1 23 36 0 2009 1 23 36 0 2009 1 23 36 0 2007 1 23 37 . 2007 1 23 37 . 2007 1 23 37 . 2007 1 23 37 . 2007 1 23 37 . 2007 1 23 37 . 2009 1 23 37 0 2009 1 23 37 0 2009 1 23 37 0 2009 1 23 37 0 2009 1 23 37 0 2009 1 23 37 0 2007 1 23 47 . 2007 1 23 47 . 2007 1 23 47 . 2009 1 23 47 0 2007 1 23 57 . 2007 1 23 57 . 2007 1 23 57 . 2007 1 23 57 . 2007 1 23 57 . 2009 1 23 57 0 2009 1 23 57 0 2009 1 23 57 0 end
0 Response to Replacing missing values with previous non-missing values [Panel data]
Post a Comment