Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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 <basur@pamfri.org> 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/

**Follow-Ups**:**RE: st: Labeling different kinds of missing observations***From:*Rituparna Basu <basur@pamfri.org>

**References**:**st: Labeling different kinds of missing observations***From:*Rituparna Basu <basur@pamfri.org>

- Prev by Date:
**RE: st: use of tempfile** - Next by Date:
**RE: st: Variance Ratio Test** - Previous by thread:
**st: Labeling different kinds of missing observations** - Next by thread:
**RE: st: Labeling different kinds of missing observations** - Index(es):