Statalist


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

st: RE: RE: replace missing in panel data


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: replace missing in panel data
Date   Mon, 30 Jun 2008 19:10:21 +0100

Wrong way round: previous non-missing value trumps following non-missing
value. 

Nick 
[email protected] 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: 30 June 2008 17:01
To: [email protected]
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
[email protected] 

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/



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