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: Replacing the missing observations


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: Replacing the missing observations
Date   Wed, 16 Nov 2011 10:24:17 +0000

This is an FAQ. 

FAQ     . . . . . . . . . . . . . . . . . . . . . . . Replacing missing values
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        9/05    How can I replace missing values with previous or
                following nonmissing values or within sequences?
                http://www.stata.com/support/faqs/data/missing.html

In this example 

bysort time (ewdiffret) : replace ewdiffret = ewdiffret[1] 

Note that -replace- is a command (not a function). 

would work. 

Nick 
[email protected] 

[email protected]

group	time	ewportret	ewdiffret

0	2007m4	.041679	             .
1	2007m4	.0375245	-.0041545
0	2007m5	.0449738	     .
1	2007m5	.0397919	-.0051819
0	2007m6	-.0240277	     .
1	2007m6	-.0188678	.0051599

The variable ewdiffret is the difference in ewportret between group 1 and 
group 0 for each time variable (thanks to Dr. Cox for the help with this). My 
question is how can i now replace all empty cells under the ewdiffret in the 
same month with the single ewdiffret value in that given month. Indeed i have 
too many empty cells in a given month and i want to replace them all with the 
single ewdiffret i have for that month.

For example: I would like to have the first empty cell under ewdiffret equal 
to -.0041545 as the time variable for both is 2007m4 and the second 
empty cell equal to -.0051819 as their time variable is 2007m5. Using too 
many replace functions takes a long time and may cause transcription errors.

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