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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

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

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

Date |
Mon, 30 Jun 2008 17:00:54 +0100 |

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/

**Follow-Ups**:**st: RE: RE: replace missing in panel data***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**st: replace missing in panel data***From:*"Dherani, Mukesh" <M.K.Dherani@liverpool.ac.uk>

- Prev by Date:
**st: Percent correctly predicted after Asclogit or Clogit** - Next by Date:
**Re: st: Running 32 Bit Stata IC 10 on 64 Bit Stata** - Previous by thread:
**st: replace missing in panel data** - Next by thread:
**st: RE: RE: replace missing in panel data** - Index(es):

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