Statalist The Stata Listserver


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

st: RE: Re: First non-zero observation within a variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Re: First non-zero observation within a variable
Date   Sun, 4 Feb 2007 17:40:10 -0000

I too just have to chime in on this one since I haven't seen 
anyone mention an FAQ with full discussion of almost the 
same problem. 

How can I drop spells of missing values at the beginning and end 
of panel data?
http://www.stata.com/support/faqs/data/dropmiss.html

A tweaking of an example there gives another one line solution
similar in spirit to Michael's: 

by group (time), sort: drop if _n == sum(mi(response) | response == 0) 

Nick 
n.j.cox@durham.ac.uk 

Michael Blasnik

> I just have to chime in on this one since I haven't seen 
> anyone mention a 
> simple one line solution:
> 
> bysort group (time): drop if sum(expression!=0 & expression<.)==0

Thomas Speidel

> >I am trying to tag the first non-zero, non-missing 
> observation within a
> > variable by group.  The goal is to drop anything BEFORE the 
> expression
> > is measured within a group.  

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index