Statalist The Stata Listserver


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

st: Re: counting and eliminating data


From   "Michael Blasnik" <michael.blasnik@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: counting and eliminating data
Date   Wed, 25 Jan 2006 10:00:26 -0500

There are a couple of approaches you could take, but I think using egen nvals is the best bet.

sort subarea
by subarea: egen nyears=nvals(year)
keep if nyears>=13
sort subarea
by subarea: egen firstfive=nvals(year) if year<=5
by subarea: egen lastfive=nvals(year) if year>21
* fill out missing values within subarea
bysort subarea (firstfive): replace firstfive=firstfive[1]
bysort subarea (lastfive): replace lastfive=lastfive[1]
keep if firstfive>=2 & lastfive>=2
drop nyears firstfive lastfive

Michael Blasnik

----- Original Message ----- From: "Jennifer Devine" <jdevine@mun.ca>
To: <statalist@hsphsun2.harvard.edu>
Sent: Wednesday, January 25, 2006 8:34 AM
Subject: st: counting and eliminating data



Can someone please set me in the right direction for coding a program to count and eliminate data if it doesn't meet a certain criteria?

I have survey data taken over 26 years and the survey area is divided into subareas. I want to only include a subarea if data was collected 13 years out of the 26 and data must have been collected 2 years of the first 5 years and 2 years of the last 5 years. If the subarea does not meet that criteria, I want Stata to drop that subarea from the analysis. At the moment, I'm having to look at everything individually and it takes several days to eliminate subareas.

Thank you,
Jennifer



Jennifer Devine
Doctoral Candidate
Memorial University of Newfoundland
St. John's, NL A1C 5S7
Canada
Tel: (709) 737-8833
Fax: (709) 737-3121

email: jdevine@mun.ca
*
*   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–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index