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]

Re: st: Labeling different kinds of missing observations


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Labeling different kinds of missing observations
Date   Thu, 19 Apr 2012 20:15:06 +0100

This sounds as if you want indicators

missbefore  1 if any missing before first non-missing and 0 otherwise

missafter     1 if any missing after etc.

Here's a sketch. Code not tested.

gen missbefore = 0
gen missafter = 0
gen first = .

qui forval J = 1/7 {
       replace missbefore = 1 if missing(Y`J') & `J' < `first'
       replace first = `J' if missing(first) & !missing(Y`J')
       replace missafter = 1 if missing(Y`J') & `J' > `first'
}

I think of these problems in this way.

1. I need to initialise an indicator. Sometimes the initial value does
not matter; sometimes it does. You have to think it through for each
problem.

2. I need to loop over the variables.

3. The first key then is "when do I change my mind?"

4. The second key is "if I change my mind, is the indicator then
fixed, or may I need to update it?"

But why not -reshape long-?

See also

SJ-9-1  pr0046  . . . . . . . . . . . . . . . . . . .  Speaking Stata: Rowwise
        (help rowsort, rowranks if installed) . . . . . . . . . . .  N. J. Cox
        Q1/09   SJ 9(1):137--157
        shows how to exploit functions, egen functions, and Mata
        for working rowwise; rowsort and rowranks are introduced

Nick

On Thu, Apr 19, 2012 at 7:10 PM, Rituparna Basu <[email protected]> wrote:

> I am trying to generate a variable that will indicate missing BEFORE FIRST YEAR of OBSERVATION and missing AFTER FIRST YEAR of OBSERVATION.
> Here is a sample of the data:
>
> ID  Y1  Y2  Y3  Y4  Y5  Y6  Y7
> 1    .      .      x    x     x     x   x
> 2    .     x      .    x     x     x   x
> 3    .      .      x    x    .     x   x
> 4    .      x     .    x     x     .   x
> 5    x     x     .   x      x     x  .
>

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