This is an FAQ.
FAQ . . . . . . . . . . . . . . . . . . . . . . . Replacing missing
values
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N.
J. Cox
2/03 How can I replace missing values with previous or
following nonmissing values?
http://www.stata.com/support/faqs/data/missing.html
-- apart from the twist about -drop-ping values which is standard stuff.
I may be in a minority, but I dislike signals of "Thanks in advance".
Courtesy is not the issue here; people who ask questions acquire the
responsibility to report on what worked and close a thread.
Nick
[email protected]
Victor, Jennifer Nicoll
I have a time series panel that has missing values. I want to copy,
duplicate, replace, or otherwise fill-in values in one variable with
other values in that variable.
For example, suppose I have variables time, state, district,
blackpopdist (black population in that district) and blackpopstate
(black population in that state. My unit of analysis is district, so
states are listed as district=0. I have blackpopdist for each
district>0, but missing for district==0. I have blackpopstate for each
district==0, but missing otherwise. I want to ultimately delete the
observations where district =0. Before I do so, I want my blackpopstate
variable to take on constant values for that state, for how ever many
districts are in it. Therefore, for each year-state, I want to
duplicate the first value in blackpopstate to fillin the other missing
value for the rest of the districts in that year-state. Then drop the
district=0 observation.
A sample starting dataset:
Time state dist blackpopdist blackpopstate
92 AL 0 . 1234
92 AL 1 234 .
92 AL 2 456 .
92 CA 0 . 4567
92 CA 1 2345 .
92 CA 2 12 .
93 AL 0 . 1235
93 AL 1 235 .
A sample complete dataset:
Time state dist blackpopdist blackpopstate
92 AL 1 234 1234
92 AL 2 456 1234
92 CA 1 2345 4567
92 CA 2 12 4567
93 AL 1 235 1235
*
* 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/