[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Dherani, Mukesh" <M.K.Dherani@liverpool.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: RE: replace missing in panel data |

Date |
Wed, 2 Jul 2008 09:34:51 +0100 |

Thanks Nick. Actually for my dataset there are only two rows of duplicates, fortunately. And yes, I have sorted dataset earlier to make sense out of it. Thanks again. BW,m -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: 30 June 2008 17:01 To: statalist@hsphsun2.harvard.edu Subject: st: RE: replace missing in panel data This is discussed in an FAQ: FAQ . . . . . . . . . . . . . . . . . . . . . . . Replacing missing values 2/03 How can I replace missing values with previous or following nonmissing values? http://www.stata.com/support/faqs/data/missing.html The answer is to use -missing()- so that you pick up string missings as well as numeric missings. By the way, I don't understand the motivation for the following rule. Suppose a variable is missing at time 42 and present at times 41 and 43. Your rule gives the priority to time 43. That seems arbitrary at best. (I assume a sensible sort order, which is not explicit in your code.) Also, your loop won't do what you want. Instead of foreach var in a1-z1 { you need foreach var of var a1-z1 { Nick n.j.cox@durham.ac.uk Dherani, Mukesh I have duplicates (based on ID and date) in my panel dataset along with missing information for many variables. I want to replace missing information with either previous [_n-1] or following [_n+1] row. The problem is that the variables are not all numeric, some of them are string. I wonder is there any way I can replace both types of variables in one go? foreach var in a1-z1{ replace `var'=`var'[_n-1] if `var'==. & duplicate==1 replace `var'=`var'[_n+1] if `var'==. & duplicate==1 } * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

- Prev by Date:
**st: RE: inequality measures, and dynamic decomposition of inequality** - Next by Date:
**st: Comparing nested regression models** - Previous by thread:
**st: svylogitgof** - Next by thread:
**st: Comparing nested regression models** - Index(es):

© Copyright 1996–2014 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |