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

st: RE: RE: replace missing in panel data

From   "Dherani, Mukesh" <>
To   <>
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.


-----Original Message-----
From: [] On Behalf Of Nick Cox
Sent: 30 June 2008 17:01
Subject: st: RE: replace missing in panel data

This is discussed in an FAQ: 

FAQ     . . . . . . . . . . . . . . . . . . . . . . . Replacing missing
        2/03    How can I replace missing values with previous or
                following nonmissing values?

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 { 


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:

*   For searches and help try:

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