Statalist The Stata Listserver


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

Re: st: RE: Quick Question on how to drop individualobservations


From   JEFFREY ROSEN <rosen.53@osu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Quick Question on how to drop individualobservations
Date   Fri, 16 Jun 2006 12:44:23 -0400

Thanks for the quick reply. Unfortunately, the code didn't work as I had hoped.

The dataset is drawn up as:

obs 1 hhold 1 rd 1
obs 2 hhold 1 rd 2
obs 3 hhold 1 rd 2
obs 4 hhold 1 rd 3

The code below will drop the observation where the hhold value and the rd value are the same. So in the above example, hhold = rd = 1 at observation 1. Observation 1 was dropped. What I would like is to drop observation 2 because in observation 2, the identifiers are the same as observation 3.

Thanks for your help,

Jeff Rosen


----- Original Message -----
From: Nick Cox <n.j.cox@durham.ac.uk>
Date: Friday, June 16, 2006 12:01 pm
Subject: st: RE: Quick Question on how to drop individual observations

> I assume that this reads  
> 
> hhold 1  rd 1
> hhold 1  rd 2
> hhold 1  rd 2
> hhold 1  rd 3
> 
> so that this example includes 4 observations. 
> 
> It sounds as if you want 
> 
> gen long obsno = _n 
> 
> gen byte different = hhold != rd 
> bysort hhid (different obsno) : drop if _n == 1 & !different 
> 
> sort obsno 
> 
> -different- is 0 if -hhold- is equal to -rd- and 1 otherwise. 
> 
> Nick 
> n.j.cox@durham.ac.uk 
> 
> JEFFREY ROSEN
> 
> > I have a very basic question. The panel set that I am using 
> > is identified by hhold and rd. A few of the observations 
> > contains the same hhold and rd. For example:
> > 
> > hhold 1
> > rd 1
> > hhold 1
> > rd 2
> > hhold 1
> > rd 2
> > hhold 1
> > rd 3
> > 
> > I would like to drop the first observation where the hhold 
> > and rd are identical. How do I do so?
> 
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index